######################################################################################
######################################################################################
#Replication code for:

#Mark T. Buntaine, Ryan Jablonski, Daniel Nielson, Paula Pickering
#SMS Texts on Corruption Help Ugandan Voters Hold Elected Councillors Accountable at the Polls

#Prepared by: Mark Buntaine
#Mark Buntaine contact (as of April 2018): buntaine@bren.ucsb.edu

#Compiled using R Version 3.4.3 (version "Kite-Eating Tree") on Mac running OS X 10.13.4
######################################################################################
######################################################################################

#options(warn=-1)
#Note: warnings turned off for the replication code log file

######################################################################################
###Packages
######################################################################################
library(lfe) #Version 2.6-2291
#Note: on warnings, see: https://cran.r-project.org/web/packages/lfe/vignettes/identification.pdf
library(stargazer) #Version 5.2.1
library(dplyr) #Version 0.7.4
library(cobalt) #Version 3.2.2
library(xtable) #Version 1.8-2

######################################################################################
###Functions
######################################################################################
felm.ri <- function(formula, dta, treat.var, rand.ob, rand.ob.info.cols, join.var, sims, ...){
  require(lfe)
  print("1. data and rand.ob must have rows organized in identical order")
  print("2. treat.var should be first right-side entry in formula")
  print("3. join.var must have identical name between data and rand.ob")
  
  ate <- coef(felm(formula, data=dta))[1]
  N <- felm(formula, data=dta)$N
  ate.samp.dist <- rep(NA,sims)
  
  for (i in 1:sims){
    dta[,treat.var] <- rand.ob[rand.ob[,join.var] %in% dta[,join.var], rand.ob.info.cols+i]
    
    ate.samp.dist[i] <- coef(felm(formula, data=dta))[1]
  }
  
  p.two.way <- sum(abs(ate)<abs(ate.samp.dist))/sims
  p.one.way.greater <- sum(ate<ate.samp.dist)/sims
  p.one.way.lesser <- sum(ate>ate.samp.dist)/sims
  se <- sd(ate.samp.dist)
  
  coun <- list("ate" = ate, "ate.samp.dist" = ate.samp.dist, "se"=se, "p.two.way" = p.two.way, "p.one.way.greater" = p.one.way.greater, "p.one.way.lesser" = p.one.way.lesser, "N" = N)
  return(coun)
}

felm.ri2 <- function(formula, dta, treat.var, rand.ob, rand.ob.info.cols, join.var, sims, ...){
  require(lfe)
  print("1. data and rand.ob must have rows organized in identical order")
  print("2. treat.var should be first right-side entry in formula")
  print("3. join.var must have identical name between data and rand.ob")
  
  #Note: have to make this for multiple factor of one randomized treatment
  
  ran.coef.num <- length(unique(dta[,treat.var][!is.na(dta[,treat.var])]))-1 #Gives number of coefficients to keep for crossed treatment indicator
  N <- felm(formula, data=dta)$N
  coef <- coef(felm(formula, data=dta))[1:ran.coef.num]
  coef.samp.dist <- matrix(data=NA, nrow=ran.coef.num, ncol=sims)
  #row.names(coef.samp.dist) <- names(coef)
  
  for (i in 1:sims){
    dta[,treat.var] <- rand.ob[rand.ob[,join.var] %in% dta[,join.var], rand.ob.info.cols+i]
    coef.samp.dist[,i] <- coef(felm(formula, data=dta))[1:ran.coef.num]
  }
  
  se <- apply(coef.samp.dist, 1, sd) #Cannot get SEs off non-randomized parameters
  
  p.two.way <- rep(NA,length(coef))
  p.one.way.greater <- rep(NA,length(coef))
  p.one.way.lesser <- rep(NA,length(coef))
  
  for (i in 1:length(coef)){
    p.two.way[i] <- sum(abs(coef[i])<abs(coef.samp.dist[i,]))/sims
    p.one.way.greater[i] <- sum(coef[i]<coef.samp.dist[i,])/sims
    p.one.way.lesser[i] <- sum(coef[i]>coef.samp.dist[i,])/sims
  }
  
  coun <- list("coef" = coef, "coef.samp.dist" = coef.samp.dist, "se"=se, "p.two.way" = p.two.way, "p.one.way.greater" = p.one.way.greater, "p.one.way.lesser" = p.one.way.lesser, "N" = N)
  return(coun)
}

felm.ri3 <- function(formula, dta, treat.var, rand.ob, rand.ob.info.cols, join.var, sims, weights, ...){
  require(lfe)
  print("1. data and rand.ob must have rows organized in identical order")
  print("2. treat.var should be first right-side entry in formula")
  print("3. join.var must have identical name between data and rand.ob")
  
  ate <- coef(felm(formula, data=dta, weights = weights))[1]
  N <- felm(formula, data=dta)$N
  ate.samp.dist <- rep(NA,sims)
  
  for (i in 1:sims){
    dta[,treat.var] <- rand.ob[rand.ob[,join.var] %in% dta[,join.var], rand.ob.info.cols+i]
    
    ate.samp.dist[i] <- coef(felm(formula, data=dta))[1]
  }
  
  p.two.way <- sum(abs(ate)<abs(ate.samp.dist))/sims
  p.one.way.greater <- sum(ate<ate.samp.dist)/sims
  p.one.way.lesser <- sum(ate>ate.samp.dist)/sims
  se <- sd(ate.samp.dist)
  
  coun <- list("ate" = ate, "ate.samp.dist" = ate.samp.dist, "se"=se, "p.two.way" = p.two.way, "p.one.way.greater" = p.one.way.greater, "p.one.way.lesser" = p.one.way.lesser, "N" = N)
  return(coun)
}

######################################################################################
###Data input
######################################################################################

#Update working directory as needed to folder with replication materials
#setwd("D:/google drive/Uganda Vote Choice project/Analysis/Replication/Replication_PNAS/")
setwd("~/Google Drive/Uganda Vote Choice project/Analysis/Replication/Replication_PNAS/")

data <- read.csv("./data/MASTER_Analysis_Anon_180424.csv", stringsAsFactors=FALSE)

Budget_RI <- read.csv("./data/Budget_RI.csv", stringsAsFactors=FALSE)
Budget_RI <- Budget_RI[match(data$id.cleaned, Budget_RI$id.cleaned),] #reordering to match "data"

Density_RI <- read.csv("./data/Density_RI.csv", stringsAsFactors=FALSE)
Density_RI <- Density_RI[match(data$id.cleaned, Density_RI$id.cleaned),] #reordering to match "data"


######################################################################################
###Data setup
######################################################################################
schooling.levels <- c("no_schooling","some_primary_s","completed_prim","some_secondary","completed_seco","some_universit","completed_univ","some_post_grad","completed_mast","refuse_to_answ")
data$r.education <- factor(data$r.How_much_schooling_have_you_co, levels=schooling.levels)

#Remaking "bd.multi.treat2" because of unwanted class conversion in "data" from read.csv()
data$bd.multi.treat2 <- ifelse(data$budget.treat==1 & data$density.treat2==1,"1.1",NA)
data$bd.multi.treat2 <- ifelse(data$budget.treat==1 & data$density.treat2==0,"1.0",data$bd.multi.treat2)
data$bd.multi.treat2 <- ifelse(data$budget.treat==0 & data$density.treat2==1,"0.1",data$bd.multi.treat2)
data$bd.multi.treat2 <- ifelse(data$budget.treat==0 & data$density.treat2==0,"0.0",data$bd.multi.treat2)

data$partyID.slim <- factor(data$partyID.slim, levels=c("nrm","opposition","independent"))

data$aligned.lc5.chair.inc.noNA <- ifelse(is.na(data$aligned.lc5.chair.inc), "missing", data$aligned.lc5.chair.inc)
data$aligned.lc5.councillor.inc.noNA <- ifelse(is.na(data$aligned.lc5.councillor.inc), "missing", data$aligned.lc5.councillor.inc)
data$aligned.lc3.chair.inc.noNA <- ifelse(is.na(data$aligned.lc3.chair.inc), "missing", data$aligned.lc3.chair.inc)
data$aligned.lc3.councillor.inc.noNA <- ifelse(is.na(data$aligned.lc3.councillor.inc), "missing", data$aligned.lc3.councillor.inc)

data$lc5.chair.inc.vote.orig <- ifelse(data$lc5.chair.party.vote==data$lc5.chair.party.orig, 1, 0)
data$lc5.councillor.inc.vote.orig <- ifelse(data$lc5.councillor.party.vote==data$lc5.councillor.party.orig, 1, 0)
#Note: "orig" variable is the party elected to the seat in 2011, regardless of subsequent party switching

#Fixed effect weights
data$fe.w <- ifelse(is.na(data$density.treat2), 1/(.5*.5), 1/(.8*.2))


######################################################################################
###Budget subsets
######################################################################################

#Prior-defined subgroups
budget.good <- subset(data, budget.actual > budget.prior | (budget.actual==budget.prior & budget.actual>=4))
budget.bad <- subset(data, budget.actual < budget.prior | (budget.actual==budget.prior & budget.actual<=2))

#These are the subgroups not defined by priors, for an extended analysis
budget.positive <- subset(data, budget.actual>=4)
budget.negative <- subset(data, budget.actual<=2)

#Main subsets: no uncontested elections, no individual incumbent switched parties and ran again in 2016, and no redistricting (includes elections w/o incumbent individual)
budget.good.lc5.chair.comp <- subset(budget.good, lc5.chair.competitive==1 & lc5.chair.party.switch==0)
budget.good.lc5.councillor.comp <- subset(budget.good, lc5.councillor.competitive==1 & lc5.councillor.party.switch==0 & is.na(lc5.councillor.redistricted2016))
budget.bad.lc5.chair.comp <- subset(budget.bad, lc5.chair.competitive==1 & lc5.chair.party.switch==0)
budget.bad.lc5.councillor.comp <- subset(budget.bad, lc5.councillor.competitive==1 & lc5.councillor.party.switch==0 & is.na(lc5.councillor.redistricted2016))
budget.positive.lc5.chair.comp <- subset(budget.positive, lc5.chair.competitive==1 & lc5.chair.party.switch==0)
budget.positive.lc5.councillor.comp <- subset(budget.positive, lc5.councillor.competitive==1 & lc5.councillor.party.switch==0 & is.na(lc5.councillor.redistricted2016))
budget.negative.lc5.chair.comp <- subset(budget.negative, lc5.chair.competitive==1 & lc5.chair.party.switch==0)
budget.negative.lc5.councillor.comp <- subset(budget.negative, lc5.councillor.competitive==1 & lc5.councillor.party.switch==0 & is.na(lc5.councillor.redistricted2016))

#Verified Recipient subgroups
budget.good.lc5.chair.comp.c <- subset(budget.good, lc5.chair.competitive==1 & lc5.chair.party.switch==0 & d.X_11_Over_the_last_several_days=="yes")
budget.good.lc5.councillor.comp.c <- subset(budget.good, lc5.councillor.competitive==1 & lc5.councillor.party.switch==0 & is.na(lc5.councillor.redistricted2016) & d.X_11_Over_the_last_several_days=="yes")
budget.bad.lc5.chair.comp.c <- subset(budget.bad, lc5.chair.competitive==1 & lc5.chair.party.switch==0 & d.X_11_Over_the_last_several_days=="yes")
budget.bad.lc5.councillor.comp.c <- subset(budget.bad, lc5.councillor.competitive==1 & lc5.councillor.party.switch==0 & is.na(lc5.councillor.redistricted2016) & d.X_11_Over_the_last_several_days=="yes")


######################################################################################
###Table S2: Conditional effects of budget treatment by trust in Twaweza and Auditor General
######################################################################################

#Models
h1a.b.1.ag <- felm(lc5.chair.inc.vote ~ budget.treat*b.trust.AG + lc5.chair.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2.ag <- felm(lc5.councillor.inc.vote ~ budget.treat*b.trust.AG + lc5.councillor.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1.ag <- felm(lc5.chair.inc.vote ~ budget.treat*b.trust.AG + lc5.chair.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2.ag <- felm(lc5.councillor.inc.vote ~ budget.treat*b.trust.AG + lc5.councillor.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)
h1a.b.1.tw <- felm(lc5.chair.inc.vote ~ budget.treat*b.trust.Twaweza + lc5.chair.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2.tw <- felm(lc5.councillor.inc.vote ~ budget.treat*b.trust.Twaweza + lc5.councillor.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1.tw <- felm(lc5.chair.inc.vote ~ budget.treat*b.trust.Twaweza + lc5.chair.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2.tw <- felm(lc5.councillor.inc.vote ~ budget.treat*b.trust.Twaweza + lc5.councillor.intent + b.Q1_living_conditions + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)

stargazer(h1a.b.1.ag, h1a.b.2.ag, h1b.b.1.ag, h1b.b.2.ag, h1a.b.1.tw, h1a.b.2.tw, h1b.b.1.tw, h1b.b.2.tw, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor","LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Trust in Auditor General","Trust in Twaweza"), column.separate = c(4,4),
          keep = c("budget.treat","b.trust.AG","b.trust.Twaweza"),
          covariate.labels = c("Budget Treatment","AG Trust: Don't Know","AG Trust: Missing","AG Trust: A Little","AG Trust: A Lot","Twaweza Trust: Don't Know","Twaweza Trust: Missing","Twaweza Trust: A Little","Twaweza Trust: A Lot", "Treatment * AG Trust: Don't Know","Treatment * AG Trust: Missing","Treatment * AG Trust: A Little","Treatment * AG Trust: A Lot", "Treatment * Twaweza Trust: Don't Know","Treatment * Twaweza Trust: Missing","Treatment * Twaweza Trust: A Little","Treatment * Twaweza Trust: A Lot"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("News Type","Good","Good","Bad","Bad","Good","Good","Bad","Bad")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          notes = "Notes: SEs clustered by politician; two-tailed tests; contested elections only without party switching by incumbent.",
          df = FALSE, omit.stat = c("rsq","ser"),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Wed, Dec 06, 2017 - 11:28:41


######################################################################################
###Table S3: Effect of treatment on reported vote choice among voters who expect free and fair district elections
######################################################################################

budget.good.lc5.chair.comp.ff <- subset(budget.good.lc5.chair.comp, (b.Q24_Powerful_ppl_learning_how_=="not_at_all_lik" | b.Q24_Powerful_ppl_learning_how_=="not_very_likel") & (b.Q25_Will_counting_votes_be_fai=="very_likely" | b.Q25_Will_counting_votes_be_fai=="somewhat_likel"))
budget.good.lc5.councillor.comp.ff <- subset(budget.good.lc5.councillor.comp, (b.Q24_Powerful_ppl_learning_how_=="not_at_all_lik" | b.Q24_Powerful_ppl_learning_how_=="not_very_likel") & (b.Q25_Will_counting_votes_be_fai=="very_likely" | b.Q25_Will_counting_votes_be_fai=="somewhat_likel"))
budget.bad.lc5.chair.comp.ff <- subset(budget.bad.lc5.chair.comp, (b.Q24_Powerful_ppl_learning_how_=="not_at_all_lik" | b.Q24_Powerful_ppl_learning_how_=="not_very_likel") & (b.Q25_Will_counting_votes_be_fai=="very_likely" | b.Q25_Will_counting_votes_be_fai=="somewhat_likel"))
budget.bad.lc5.councillor.comp.ff <- subset(budget.bad.lc5.councillor.comp, (b.Q24_Powerful_ppl_learning_how_=="not_at_all_lik" | b.Q24_Powerful_ppl_learning_how_=="not_very_likel") & (b.Q25_Will_counting_votes_be_fai=="very_likely" | b.Q25_Will_counting_votes_be_fai=="somewhat_likel"))

h1a.b.1ff <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp.ff)
h1a.b.2ff <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp.ff)
h1b.b.1ff <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp.ff)
h1b.b.2ff <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp.ff)

chair.good.ff <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name,
                         dta=budget.good.lc5.chair.comp.ff, treat.var = "budget.treat", rand.ob=Budget_RI, 
                         rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.good.ff <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name,
                        dta=budget.good.lc5.councillor.comp.ff, treat.var = "budget.treat", rand.ob=Budget_RI, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.bad.ff <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                        dta=budget.bad.lc5.chair.comp.ff, treat.var = "budget.treat", rand.ob=Budget_RI, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.bad.ff <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                       dta=budget.bad.lc5.councillor.comp.ff, treat.var = "budget.treat", rand.ob=Budget_RI, 
                       rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

stargazer(h1a.b.1ff, h1a.b.2ff, h1b.b.1ff, h1b.b.2ff, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(2,2),
          keep = c("budget.treat","lc5.chair.intent","lc5.councillor.intent"),
          add.lines = list(c("Polling station fixed effects", "Yes", "Yes","Yes","Yes"),
                           c("Covariates", "Yes", "Yes","Yes","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Budget Treatment","LC5 Chair Intent","LC5 Councillor Intent"),
          notes = "Notes: SEs on treatment derived from randomization inference using exact clustered design; SEs on covariates clustered by politician; one-tailed tests as pre-registered; contested elections only with incumbent who did not switch party.",
          df = FALSE, omit.stat = c("rsq","ser"),
          p = list(chair.good.ff$p.one.way.greater,
                   coun.good.ff$p.one.way.greater,
                   chair.bad.ff$p.one.way.lesser,
                   coun.bad.ff$p.one.way.lesser),
          se = list(c(chair.good.ff$se,as.numeric(h1a.b.1ff$cse[2])),
                    c(coun.good.ff$se,as.numeric(h1a.b.2ff$cse[2])),
                    c(chair.bad.ff$se,as.numeric(h1b.b.1ff$cse[2])),
                    c(coun.bad.ff$se,as.numeric(h1b.b.2ff$cse[2]))),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Wed, Dec 06, 2017 - 13:27:00


######################################################################################
###Table S4: Conditional effects of budget treatment by unsure budget prior
######################################################################################

h1a.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
p1 <- ifelse(h1a.b.1$coef[1]>0, summary(h1a.b.1)$coef[1,4]/2, 1-summary(h1a.b.1)$coef[1,4]/2)

h1a.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
p2 <- ifelse(h1a.b.2$coef[1]>0, summary(h1a.b.2)$coef[1,4]/2, 1-summary(h1a.b.2)$coef[1,4]/2)

h1b.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
p3 <- ifelse(h1b.b.1$coef[1]<0, summary(h1b.b.1)$coef[1,4]/2, 1-summary(h1b.b.1)$coef[1,4]/2)

h1b.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)
p4 <- ifelse(h1b.b.2$coef[1]<0, summary(h1b.b.2)$coef[1,4]/2, 1-summary(h1b.b.2)$coef[1,4]/2)

h1a.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
p5 <- ifelse(h1a.b.1c$coef[1]>0, summary(h1a.b.1c)$coef[1,4]/2, 1-summary(h1a.b.1c)$coef[1,4]/2)

h1a.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
p6 <- ifelse(h1a.b.2c$coef[1]>0, summary(h1a.b.2c)$coef[1,4]/2, 1-summary(h1a.b.2c)$coef[1,4]/2)

h1b.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
p7 <- ifelse(h1b.b.1c$coef[1]<0, summary(h1b.b.1c)$coef[1,4]/2, 1-summary(h1b.b.1c)$coef[1,4]/2)

h1b.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat*budget.prior.dontknow + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)
p8 <- ifelse(h1b.b.2c$coef[1]<0, summary(h1b.b.2c)$coef[1,4]/2, 1-summary(h1b.b.2c)$coef[1,4]/2)

#Table for eight models with & without covariates
stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          keep = c("budget.treat","budget.prior.dontknow","lc5.chair.intent","lc5.councillor.intent"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates", "No","Yes","No","Yes","No","Yes","No","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Budget Treatment","Unsure Budget Prior","LC5 Chair Intent","LC5 Councillor Intent","Budget Treatment * Unsure Budget Prior"),
          notes = "Notes: SEs clustered by politician; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Sat, Dec 09, 2017 - 14:55:02


######################################################################################
###Table S5: Treatment effects of information type unconditional on respondents' priors
######################################################################################

h1a.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.positive.lc5.chair.comp)
p1 <- ifelse(h1a.b.1$coef[1]>0, summary(h1a.b.1)$coef[1,4]/2, 1-summary(h1a.b.1)$coef[1,4]/2)

h1a.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.positive.lc5.councillor.comp)
p2 <- ifelse(h1a.b.2$coef[1]>0, summary(h1a.b.2)$coef[1,4]/2, 1-summary(h1a.b.2)$coef[1,4]/2)

h1b.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.negative.lc5.chair.comp)
p3 <- ifelse(h1b.b.1$coef[1]<0, summary(h1b.b.1)$coef[1,4]/2, 1-summary(h1b.b.1)$coef[1,4]/2)

h1b.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.negative.lc5.councillor.comp)
p4 <- ifelse(h1b.b.2$coef[1]<0, summary(h1b.b.2)$coef[1,4]/2, 1-summary(h1b.b.2)$coef[1,4]/2)

h1a.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.positive.lc5.chair.comp)
p5 <- ifelse(h1a.b.1c$coef[1]>0, summary(h1a.b.1c)$coef[1,4]/2, 1-summary(h1a.b.1c)$coef[1,4]/2)

h1a.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.positive.lc5.councillor.comp)
p6 <- ifelse(h1a.b.2c$coef[1]>0, summary(h1a.b.2c)$coef[1,4]/2, 1-summary(h1a.b.2c)$coef[1,4]/2)

h1b.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.negative.lc5.chair.comp)
p7 <- ifelse(h1b.b.1c$coef[1]<0, summary(h1b.b.1c)$coef[1,4]/2, 1-summary(h1b.b.1c)$coef[1,4]/2)

h1b.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.negative.lc5.councillor.comp)
p8 <- ifelse(h1b.b.2c$coef[1]<0, summary(h1b.b.2c)$coef[1,4]/2, 1-summary(h1b.b.2c)$coef[1,4]/2)

#Table for eight models with & without covariates
stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          keep = c("budget.treat","lc5.chair.intent","lc5.councillor.intent"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates", "No","Yes","No","Yes","No","Yes","No","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Budget Treatment","LC5 Chair Intent","LC5 Councillor Intent"),
          notes = "Notes: SEs clustered by politician; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          p = list(p1,p5,p2,p6,p3,p7,p4,p8),
          se = list(h1a.b.1$cse[1:2],
                    h1a.b.1c$cse[1:2],
                    h1a.b.2$cse[1:2],
                    h1a.b.2c$cse[1:2],
                    h1b.b.1$cse[1:2],
                    h1b.b.1c$cse[1:2],
                    h1b.b.2$cse[1:2],
                    h1b.b.2c$cse[1:2]),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Mon, Dec 11, 2017 - 14:08:12


######################################################################################
###Table S6: Balance on all pre-treatment covariates by budget treatment status (matching Fig. S10)
######################################################################################

###Note: the cleaning step is an exact copy of the replication code for SI Fig. S10
###Cleaning the data and levels
covs0 <- data[,c("budget.treat",
                 "b.Q1_living_conditions",
                 "lc5.councillor.same.tribe",
                 "lc5.turnout.intent",
                 "lc5.councillor.intent",
                 "lc5.chair.intent",
                 "partyID",
                 "party.attachment",
                 "b.Q11_2011_Vote_for_LC5councilor",
                 "b.Q12_2011_vote_for_LC5chair",
                 "b.vote.buying",
                 "budget.importance",
                 "ps.importance",
                 "b.Q18_Most_important_public_serv",
                 "b.Q19_Second_most_important_publ",
                 "b.Q21a_Trust_in_politicians_for_",
                 "b.trust.Twaweza",
                 "b.Q21c_Trust_in_NGOs_for_info",
                 "b.trust.AG",
                 "b.Q22_LC5_record_of_budget_mgmt",
                 "budget.certainty",
                 "b.Q24_Powerful_ppl_learning_how_",
                 "b.Q25_Will_counting_votes_be_fai",
                 "r.What_is_your_gender",
                 "r.education",
                 "r.In_which_language_would_you_pr",
                 "r.What_is_your_age",
                 "d.attr")
              ]

##Changing variable names for plot labeling
#names(covs0)
names(covs0) <- c("budget.treat","Living Conditions","Same Tribe Councillor","Turnout Intent","Councillor Vote Intent",
               "Chair Vote Intent","Party","Party Attachment","Voted for Councillor 2011","Voted for Chair 2011","Vote Buying",
               "Budget Importance","Services Importance","Most Important Service","Second Important Service","Trust Local Politicians",
               "Trust Twaweza","Trust NGOs","Trust Auditor General","Budget Prior","Budget Prior Certainty","Voting Secret","Vote Count Fair",
               "Gender","Education","Language","Age")

##Changing labels within variables
cols <- 2:26
covs0[,cols] = apply(covs0[,cols], 2, function(x) (as.character(x)))

table(covs0[,2], useNA="always")
covs0[covs0=="don_t_know"] <- "don't know"
covs0[covs0=="much_better"] <- "much better"
covs0[covs0=="much_worse"] <- "much worse"
covs0[covs0=="refused_to_ans"] <- "refused"
covs0[covs0=="the_same"] <- "same"
table(covs0[,3], useNA="always")
covs0[,3] <- ifelse(is.na(covs0[,3]),"missing",covs0[,3])
covs0[,3] <- ifelse(covs0[,3]==" 1","yes",covs0[,3])
covs0[,3] <- ifelse(covs0[,3]==" 0","no",covs0[,3])
table(covs0[,4], useNA="always")
covs0[,4] <- ifelse(covs0[,4]==" 1","yes",covs0[,4])
covs0[,4] <- ifelse(covs0[,4]==" 0","no",covs0[,4])
covs0[,4] <- ifelse(is.na(covs0[,4]),"missing",covs0[,4])
table(covs0[,5], useNA="always")
covs0[,5] <- ifelse(covs0[,5]==" 1","yes",covs0[,5])
covs0[,5] <- ifelse(covs0[,5]==" 0","no",covs0[,5])
covs0[,5] <- ifelse(is.na(covs0[,5]),"missing",covs0[,5])
table(covs0[,6], useNA="always")
covs0[,6] <- ifelse(covs0[,6]==" 1","yes",covs0[,6])
covs0[,6] <- ifelse(covs0[,6]==" 0","no",covs0[,6])
covs0[,6] <- ifelse(is.na(covs0[,6]),"missing",covs0[,6])
table(covs0[,7], useNA="always")
covs0[,7] <- ifelse(covs0[,7]=="other-noincumbentpartymatch","other",covs0[,7])
covs0[,7] <- ifelse(is.na(covs0[,7]),"missing",covs0[,7])
table(covs0[,8], useNA="always")
covs0[,8] <- ifelse(covs0[,8]=="1","1 (very little)",covs0[,8])
covs0[,8] <- ifelse(covs0[,8]=="7","7 (very much)",covs0[,8])
covs0[,8] <- ifelse(covs0[,8]=="not_applicable","no party",covs0[,8])
table(covs0[,9], useNA="always")
covs0[covs0=="i_did_not_vote"] <- "didn't vote"
covs0[covs0==""] <- "missing"
table(covs0[,10], useNA="always")
table(covs0[,11], useNA="always")
covs0[covs0=="somewhat_likel"] <- "somewhat likely"
covs0[covs0=="somewhat_unlik"] <- "somewhat unlikely"
covs0[covs0=="very_likel"] <- "very likely"
covs0[covs0=="very_unlikely"] <- "very unlikely"
table(covs0[,12], useNA="always")
covs0[covs0=="not_important"] <- "not important"
covs0[covs0=="not_very_impor"] <- "not very important"
covs0[covs0=="somewhat_impor"] <- "somewhat important"
covs0[covs0=="very_important"] <- "very important"
table(covs0[,13], useNA="always")
covs0[is.na(covs0)] <- "missing"
table(covs0[,14], useNA="always")
covs0[covs0=="local_health_services"] <- "health"
covs0[covs0=="local_roads"] <- "roads"
covs0[covs0=="primary_schools"] <- "schools"
covs0[covs0=="water_access"] <- "water"
covs0[covs0=="refused_to_answer"] <- "refused"
table(covs0[,15], useNA="always")
covs0[covs0=="local_health_s"] <- "health"
covs0[covs0=="primary_school"] <- "schools"
table(covs0[,16], useNA="always")
covs0[covs0=="do_not_trust_a"] <- "don't trust at all"
covs0[covs0=="option_5"] <- "refused"
covs0[covs0=="trust_a_little"] <- "trust a little"
covs0[covs0=="trust_a_lot"] <- "trust a lot"
table(covs0[,17], useNA="always")
table(covs0[,18], useNA="always")
table(covs0[,19], useNA="always")
table(covs0[,20], useNA="always")
covs0[covs0=="a_little_worse"] <- "a little worse"
table(covs0[,21], useNA="always")
covs0[covs0=="not_certain"] <- "not certain"
covs0[covs0=="very_certain"] <- "very certain"
covs0[covs0=="very_uncertain"] <- "very uncertain"
table(covs0[,22], useNA="always")
covs0[covs0=="not_at_all_lik"] <- "not at all likely"
covs0[covs0=="not_very_likel"] <- "not very likely"
covs0[covs0=="very_likely"] <- "very likely"
table(covs0[,23], useNA="always")
table(covs0[,24], useNA="always")
table(covs0[,25], useNA="always")
covs0[covs0=="completed_mast"] <- "complete graduate"
covs0[covs0=="completed_prim"] <- "complete primary"
covs0[covs0=="completed_seco"] <- "complete secondary"
covs0[covs0=="completed_univ"] <- "complete university"
covs0[covs0=="no_schooling"] <- "no schooling"
covs0[covs0=="refuse_to_answ"] <- "refused"
covs0[covs0=="some_post_grad"] <- "some graduate"
covs0[covs0=="some_primary_s"] <- "some primary"
covs0[covs0=="some_secondary"] <- "some secondary"
covs0[covs0=="some_universit"] <- "some university"
table(covs0[,26], useNA="always") #Rename these in letters
covs0[,26] <- ifelse(covs0[,26]!="luganda" & covs0[,26]!="english" & covs0[,26]!="runyankole" & covs0[,26]!="langi" & covs0[,26]!="ateso", "other", covs0[,26])
covs0[covs0=="AUTOMATIC"] <- "other"
table(covs0[,27], useNA="always")

##Creating factors with appropriate levels
table(covs0[,2], useNA="always")
covs0[,2] <- factor(covs0[,2], levels=rev(c("much better","better","same","worse","much worse","don't know","missing","refused")))
sort(table(covs0[,7]))
covs0[,7] <- factor(covs0[,7], levels=c("missing","ufa","other","upc","dp","fdc","independent","nrm"))
covs0[,8] <- factor(covs0[,8], levels=rev(c("7 (very much)","6","5","4","3","2","1 (very little)","no party","missing")))
covs0[,9] <- factor(covs0[,9], levels=c("missing","refused","don't know","didn't vote","no","yes"))
covs0[,10] <- factor(covs0[,10], levels=c("missing","refused","don't know","didn't vote","no","yes"))
covs0[,11] <- factor(covs0[,11], levels=c("missing","don't know","very likely","somewhat likely","somewhat unlikely","very unlikely"))
covs0[,14] <- factor(covs0[,14], levels=c("missing","refused","don't know","schools","roads","water","health"))
covs0[,15] <- factor(covs0[,15], levels=c("missing","refused","don't know","schools","roads","water","health"))
covs0[,16] <- factor(covs0[,16], levels=c("missing","refused","don't know","don't trust at all","trust a little","trust a lot"))
covs0[,17] <- factor(covs0[,17], levels=c("missing","refused","don't know","don't trust at all","trust a little","trust a lot"))
covs0[,18] <- factor(covs0[,18], levels=c("missing","refused","don't know","don't trust at all","trust a little","trust a lot"))
covs0[,19] <- factor(covs0[,19], levels=c("missing","refused","don't know","don't trust at all","trust a little","trust a lot"))
covs0[,20] <- factor(covs0[,20], levels=c("missing","refused","much worse","a little worse","don't know","better","much better"))
covs0[,21] <- factor(covs0[,21], levels=c("missing","very uncertain","not certain","certain","very certain"))
covs0[,22] <- factor(covs0[,22], levels=c("missing","refused","don't know","not at all likely","not very likely","somewhat likely","very likely"))
covs0[,23] <- factor(covs0[,23], levels=c("missing","refused","don't know","not at all likely","not very likely","somewhat likely","very likely"))
covs0[,25] <- factor(covs0[,25], levels=c("refused","no schooling","some primary","complete primary","some secondary","complete secondary","some university","complete university","some graduate","complete graduate"))
covs0[,26] <- factor(covs0[,26], levels=c("other","ateso","langi","runyankole","english","luganda"))

btab <- bal.tab(covs0[2:27], treat=covs0$budget.treat, disp.means=TRUE, quick=TRUE, s.d.denom="control")

options(scipen=999)

balance=btab$Balance
balance$id=(1:nrow(balance))
balance$treat = balance$M.1.Un
balance$control = balance$M.0.Un
balance$difference = balance$Diff.Un
balance=balance[,c("treat", "control", "difference")]
balance <- balance[rev(order(balance$difference)),]

N=16083
N.t <- 8064
N.c <- 8019
balance$v1=((balance$treat)*(1-balance$treat)/N.t)
balance$v2=((balance$control)*(1-balance$control)/N.c)
balance$v3=balance$v1+balance$v2

balance$treat=paste(round(balance$treat, 4), "  (", round(sqrt(balance$v1),4), ")", sep="")
balance$control=paste(round(balance$control, 4), "  (", round(sqrt(balance$v2),4), ")", sep="")
balance$difference=paste(round(balance$difference, 4), "  (", round(sqrt(balance$v3),4), ")", sep="")

balance$id=NULL
balance$v1=NULL
balance$v2=NULL
balance$v3=NULL

#Manually computing standard errors for the one continuous variable, entered manually in table
age.treat.se <- sd(covs0$Age[covs0$budget.treat==1])/sqrt(length(covs0$Age[covs0$budget.treat==1]))
age.control.se <- sd(covs0$Age[covs0$budget.treat==0])/sqrt(length(covs0$Age[covs0$budget.treat==0]))
age.diff.se <- sqrt(age.treat.se+age.control.se)

xtable(balance)

options(scipen=0)


######################################################################################
###Table S7: Distribution of voter party identification, politician party identification, and alignment by news group for main estimation
######################################################################################

budget.good.lc5.chair.comp.complete <- subset(budget.good.lc5.chair.comp, !is.na(lc5.chair.inc.vote) & !is.na(budget.treat) & !is.na(lc5.chair.intent) & !is.na(lc5.chair.name))
budget.good.lc5.councillor.comp.complete <- subset(budget.good.lc5.councillor.comp, !is.na(lc5.councillor.inc.vote) & !is.na(budget.treat) & !is.na(lc5.councillor.intent) & !is.na(lc5.councillor.name))
budget.bad.lc5.chair.comp.complete <- subset(budget.bad.lc5.chair.comp, !is.na(lc5.chair.inc.vote) & !is.na(budget.treat) & !is.na(lc5.chair.intent) & !is.na(lc5.chair.name))
budget.bad.lc5.councillor.comp.complete <- subset(budget.bad.lc5.councillor.comp, !is.na(lc5.councillor.inc.vote) & !is.na(budget.treat) & !is.na(lc5.councillor.intent) & !is.na(lc5.councillor.name))

budget.good.lc5.chair.comp.complete$partyID=ifelse(budget.good.lc5.chair.comp.complete$partyID=="upc", "other", budget.good.lc5.chair.comp.complete$partyID)
budget.good.lc5.chair.comp.complete$partyID=ifelse(budget.good.lc5.chair.comp.complete$partyID=="ufa", "other", budget.good.lc5.chair.comp.complete$partyID)
budget.good.lc5.chair.comp.complete$partyID=ifelse(budget.good.lc5.chair.comp.complete$partyID=="other-noincumbentpartymatch", "other", budget.good.lc5.chair.comp.complete$partyID)
xtabs(~budget.good.lc5.chair.comp.complete$partyID)

budget.good.lc5.councillor.comp.complete$partyID=ifelse(budget.good.lc5.councillor.comp.complete$partyID=="upc", "other", budget.good.lc5.councillor.comp.complete$partyID)
budget.good.lc5.councillor.comp.complete$partyID=ifelse(budget.good.lc5.councillor.comp.complete$partyID=="ufa", "other", budget.good.lc5.councillor.comp.complete$partyID)
budget.good.lc5.councillor.comp.complete$partyID=ifelse(budget.good.lc5.councillor.comp.complete$partyID=="other-noincumbentpartymatch", "other", budget.good.lc5.councillor.comp.complete$partyID)
xtabs(~budget.good.lc5.councillor.comp.complete$partyID)

budget.bad.lc5.chair.comp.complete$partyID=ifelse(budget.bad.lc5.chair.comp.complete$partyID=="upc", "other", budget.bad.lc5.chair.comp.complete$partyID)
budget.bad.lc5.chair.comp.complete$partyID=ifelse(budget.bad.lc5.chair.comp.complete$partyID=="ufa", "other", budget.bad.lc5.chair.comp.complete$partyID)
budget.bad.lc5.chair.comp.complete$partyID=ifelse(budget.bad.lc5.chair.comp.complete$partyID=="other-noincumbentpartymatch", "other", budget.bad.lc5.chair.comp.complete$partyID)
xtabs(~budget.bad.lc5.chair.comp.complete$partyID)

budget.bad.lc5.councillor.comp.complete$partyID=ifelse(budget.bad.lc5.councillor.comp.complete$partyID=="upc", "other", budget.bad.lc5.councillor.comp.complete$partyID)
budget.bad.lc5.councillor.comp.complete$partyID=ifelse(budget.bad.lc5.councillor.comp.complete$partyID=="ufa", "other", budget.bad.lc5.councillor.comp.complete$partyID)
budget.bad.lc5.councillor.comp.complete$partyID=ifelse(budget.bad.lc5.councillor.comp.complete$partyID=="other-noincumbentpartymatch", "other", budget.bad.lc5.councillor.comp.complete$partyID)
xtabs(~budget.bad.lc5.councillor.comp.complete$partyID)

t1.P=prop.table(sort(table(budget.good.lc5.chair.comp.complete$partyID), decreasing=TRUE))
t1.N=sort(table(budget.good.lc5.chair.comp.complete$partyID), decreasing=TRUE)

t2.P=prop.table(sort(table(budget.bad.lc5.chair.comp.complete$partyID), decreasing=TRUE))
t2.N=sort(table(budget.bad.lc5.chair.comp.complete$partyID), decreasing=TRUE)

t3.P=prop.table(sort(table(budget.good.lc5.councillor.comp.complete$partyID), decreasing=TRUE))
t3.N=sort(table(budget.good.lc5.councillor.comp.complete$partyID), decreasing=TRUE)

t4.P=prop.table(sort(table(budget.bad.lc5.councillor.comp.complete$partyID), decreasing=TRUE))
t4.N=sort(table(budget.bad.lc5.councillor.comp.complete$partyID), decreasing=TRUE)

##Incumbent Party ID
t5.P=prop.table(sort(table(budget.good.lc5.chair.comp.complete$lc5.chair.party), decreasing=TRUE))
t5.N=(sort(table(budget.good.lc5.chair.comp.complete$lc5.chair.party), decreasing=TRUE))

t6.P=prop.table(sort(table(budget.bad.lc5.chair.comp.complete$lc5.chair.party), decreasing=TRUE))
t6.N=(sort(table(budget.bad.lc5.chair.comp.complete$lc5.chair.party), decreasing=TRUE))

t7.P=prop.table(sort(table(budget.good.lc5.councillor.comp.complete$lc5.councillor.party), decreasing=TRUE))
t7.N=(sort(table(budget.good.lc5.councillor.comp.complete$lc5.councillor.party), decreasing=TRUE))

t8.P=prop.table(sort(table(budget.bad.lc5.councillor.comp.complete$lc5.councillor.party), decreasing=TRUE))
t8.N=(sort(table(budget.bad.lc5.councillor.comp.complete$lc5.councillor.party), decreasing=TRUE))

##Voter-Incumbent Alignment
t9.P=prop.table(sort(table(budget.good.lc5.chair.comp.complete$aligned.lc5.chair.inc), decreasing=TRUE))
t9.N=(sort(table(budget.good.lc5.chair.comp.complete$aligned.lc5.chair.inc), decreasing=TRUE))

t10.P=prop.table(sort(table(budget.bad.lc5.chair.comp.complete$aligned.lc5.chair.inc), decreasing=TRUE))
t10.N=(sort(table(budget.bad.lc5.chair.comp.complete$aligned.lc5.chair.inc), decreasing=TRUE))

t11.P=prop.table(sort(table(budget.good.lc5.chair.comp.complete$aligned.lc5.councillor.inc), decreasing=TRUE))
t11.N=(sort(table(budget.good.lc5.chair.comp.complete$aligned.lc5.councillor.inc), decreasing=TRUE))

t12.P=prop.table(sort(table(budget.bad.lc5.chair.comp.complete$aligned.lc5.councillor.inc), decreasing=TRUE))
t12.N=(sort(table(budget.bad.lc5.chair.comp.complete$aligned.lc5.councillor.inc), decreasing=TRUE))

#totals
t13.N=nrow(budget.good.lc5.chair.comp.complete)
t14.N=nrow(budget.bad.lc5.chair.comp.complete)

t15.N=nrow(budget.good.lc5.councillor.comp.complete)
t16.N=nrow(budget.bad.lc5.councillor.comp.complete)

for(i in 1:8){
  N=eval(parse(text=paste("data.frame(t",i,".N)[,2]", sep="")))
  P=eval(parse(text=paste("data.frame(t",i,".P)[,2]", sep="")))
  S=paste(N, " (", round(P, 2)*100, "%)", sep="")
  assign(paste("t", i, sep=""), data.frame(S))
}

for(i in 9:12){
  N=eval(parse(text=paste("data.frame(t",i,".N)[1,2]", sep="")))
  P=eval(parse(text=paste("data.frame(t",i,".P)[1,2]", sep="")))
  S=paste(N, " (", round(P, 2)*100, "%)", sep="")
  assign(paste("t", i, sep=""), data.frame(S))
}

partylabels.councillor=c("Party ID voter: NRM", "Party ID voter: Independent", "Party ID voter: FDC", "Party ID voter: DP", "Party ID voter: Other", "Party ID Incumbent: NRM", "Party ID Incumbent: Independent", "Party ID Incumbent: FDC", "Party ID Incumbent: DP", "Party ID Incumbent: Other", "Voter-Incumbent Alignment", "Total Responses")
partylabels.chair=c("Party ID voter: NRM", "Party ID voter: Independent", "Party ID voter: FDC", "Party ID voter: DP", "Party ID voter: Other", "Party ID Incumbent: NRM", "Party ID Incumbent: Independent", "Party ID Incumbent: FDC", "Voter-Incumbent Alignment", "Total Responses")

headers=c("Good News", "Bad News")

tab.chair=NULL
tab.chair=rbind(data.frame(t1,t2), data.frame(t5,t6))
tab.align=data.frame( t9[1],t10[1])
names(tab.align)=names(tab.chair)
tab.tot=data.frame(toString(t13.N),toString(t14.N))
names(tab.tot)=names(tab.chair)
tab.chair=rbind(tab.chair, tab.align, tab.tot)
names(tab.chair)=headers
row.names(tab.chair)=partylabels.chair

tab.councillor=NULL
tab.councillor=rbind(data.frame(t3,t4), data.frame(t7,t8))
tab.align=data.frame(t11[1],t12[1])
names(tab.align)=names(tab.councillor)
tab.tot=data.frame(toString(t15.N),toString(t16.N))
names(tab.tot)=names(tab.councillor)
tab.councillor=rbind(tab.councillor, tab.align, tab.tot)
names(tab.councillor)=headers
row.names(tab.councillor)=partylabels.councillor

print(xtable(tab.chair))
print(xtable(tab.councillor))


######################################################################################
###Table S8: Attrition with respect to the budget treatment
######################################################################################

d.attr.tab <- table(data$budget.treat,data$d.attr)
d.attr.tab

chisq.test(d.attr.tab)

d.attr.prop <- prop.table(d.attr.tab, margin=1)
d.attr.prop


######################################################################################
###Table S9: Attrition with respect to the budget treatment and density
######################################################################################

d.attr.tab <- table(data$bd.multi.treat,data$d.attr)
d.attr.tab

chisq.test(d.attr.tab)

d.attr.prop <- prop.table(d.attr.tab, margin=1)
d.attr.prop


######################################################################################
###Table S10: Treatment effects on reported turnout
######################################################################################

h7a.b.1 <- felm(lc5.turnout ~ budget.treat + lc5.turnout.intent | location.id | 0 | district_lower, data=budget.good)
h7b.b.1 <- felm(lc5.turnout ~ budget.treat + lc5.turnout.intent | location.id | 0 | district_lower, data=budget.bad)
h7a.b.1c <- felm(lc5.turnout ~ budget.treat + lc5.turnout.intent + b.Q1_living_conditions + turnout.2011.LC5 + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | district_lower, data=budget.good)
h7b.b.1c <- felm(lc5.turnout ~ budget.treat + lc5.turnout.intent + b.Q1_living_conditions + turnout.2011.LC5 + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | district_lower, data=budget.bad)

lc5.turnout.good <- felm.ri(lc5.turnout ~ budget.treat + lc5.turnout.intent | location.id | 0 | district_lower,
                            dta=budget.good, treat.var = "budget.treat", rand.ob=Budget_RI, 
                            rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

lc5.turnout.good.cov <- felm.ri(lc5.turnout ~ budget.treat + lc5.turnout.intent + b.Q1_living_conditions + turnout.2011.LC5 + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | district_lower,
                                dta=budget.good, treat.var = "budget.treat", rand.ob=Budget_RI, 
                                rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

lc5.turnout.bad <- felm.ri(lc5.turnout ~ budget.treat + lc5.turnout.intent | location.id | 0 | district_lower, 
                           dta=budget.bad, treat.var = "budget.treat", rand.ob=Budget_RI, 
                           rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

lc5.turnout.bad.cov <- felm.ri(lc5.turnout ~ budget.treat + lc5.turnout.intent + b.Q1_living_conditions + turnout.2011.LC5 + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | district_lower, 
                               dta=budget.bad, treat.var = "budget.treat", rand.ob=Budget_RI, 
                               rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)


stargazer(h7a.b.1, h7a.b.1c, h7b.b.1, h7b.b.1c, type = "latex", 
          dep.var.labels.include = FALSE,
          column.labels = c("Good News","Bad News"), column.separate = c(2,2),
          keep = c("budget.treat","lc5.turnout.intent"),
          covariate.labels = c("Budget Treatment (RI)","Turnout Intent"),
          add.lines = list(c("Polling station fixed effects", "Yes", "Yes","Yes","Yes"),
                           c("Covariates", "No", "Yes","No","Yes")),
          dep.var.caption  = "DV: Turnout for LC5 Election",
          notes = "Notes: SEs derived from randomization inference for treatment and clustered by politician for all other covariates; one-tailed tests for treatment as pre-registered.",
          df = FALSE, omit.stat = c("rsq","ser"),
          se = list(c(lc5.turnout.good$se,as.numeric(h7a.b.1$cse[2])),
                    c(lc5.turnout.good.cov$se,as.numeric(h7a.b.1c$cse[2])),
                    c(lc5.turnout.bad$se,as.numeric(h7b.b.1$cse[2])),
                    c(lc5.turnout.bad$se,as.numeric(h7b.b.1c$cse[2]))
          ),
          p = c(lc5.turnout.good$p.one.way.greater,
                lc5.turnout.good.cov$p.one.way.greater,
                lc5.turnout.bad$p.one.way.lesser,
                lc5.turnout.bad.cov$p.one.way.lesser),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Fri, Dec 15, 2017 - 09:41:46


######################################################################################
###Table S11: Treatment effect on reported vote choice for the incumbent, including non-turnout as non-positive outcome
######################################################################################

h1a.b.1c.wt <- felm(lc5.chair.inc.vote.w.turnout ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2c.wt <- felm(lc5.councillor.inc.vote.w.turnout ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1c.wt <- felm(lc5.chair.inc.vote.w.turnout ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2c.wt <- felm(lc5.councillor.inc.vote.w.turnout ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)

h1a.b.1c.wt.ri <- felm.ri(lc5.chair.inc.vote.w.turnout ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                          dta=budget.good.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

h1a.b.2c.wt.ri <- felm.ri(lc5.councillor.inc.vote.w.turnout ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                          dta=budget.good.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

h1b.b.1c.wt.ri <- felm.ri(lc5.chair.inc.vote.w.turnout ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                          dta=budget.bad.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

h1b.b.2c.wt.ri <- felm.ri(lc5.councillor.inc.vote.w.turnout ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                          dta=budget.bad.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

#Table for four models with covariates
stargazer(h1a.b.1c.wt, h1a.b.2c.wt, h1b.b.1c.wt, h1b.b.2c.wt, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(2,2),
          keep = c("budget.treat","lc5.chair.intent","lc5.councillor.intent"),
          add.lines = list(c("Polling station fixed effects", "Yes", "Yes","Yes","Yes"),
                           c("Covariates", "Yes", "Yes","Yes","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent Including Turnout",
          covariate.labels = c("Budget Treatment (RI)","LC5 Chair Intent","LC5 Councillor Intent"),
          notes.label = "Notes: SEs derived from randomization inference using exact clustered design; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          se = list(c(h1a.b.1c.wt.ri$se,h1a.b.1c.wt$cse[[2]]),
                    c(h1a.b.2c.wt.ri$se,h1a.b.2c.wt$cse[[2]]),
                    c(h1b.b.1c.wt.ri$se,h1b.b.1c.wt$cse[[2]]),
                    c(h1b.b.2c.wt.ri$se,h1b.b.2c.wt$cse[[2]])),
          p = c(h1a.b.1c.wt.ri$p.one.way.greater,
                h1a.b.2c.wt.ri$p.one.way.greater,
                h1b.b.1c.wt.ri$p.one.way.lesser,
                h1b.b.2c.wt.ri$p.one.way.lesser),
          report = c('vcsp')
) # Date and time: Thu, Nov 16, 2017 - 12:43:14


######################################################################################
###Table S12: Conditional effects of budget treatment based on the party identification of the voter
######################################################################################

h1a.b.1c.vp <- felm(lc5.chair.inc.vote ~ budget.treat*partyID.slim + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2c.vp <- felm(lc5.councillor.inc.vote ~ budget.treat*partyID.slim + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1c.vp <- felm(lc5.chair.inc.vote ~ budget.treat*partyID.slim + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2c.vp <- felm(lc5.councillor.inc.vote ~ budget.treat*partyID.slim + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)

stargazer(h1a.b.1c.vp, h1a.b.2c.vp, h1b.b.1c.vp, h1b.b.2c.vp, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(2,2),
          keep = c("budget.treat","partyID.slim"),
          covariate.labels = c("Budget Treatment","Opposition Voter","Independent Voter","Budget Treatment * Opposition Voter","Budget Treatment * Independent Voter"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes"),
                           c("Covariates", "Yes", "Yes","Yes","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          notes = "Notes: SEs clustered by politician; two-tailed tests; contested elections only without party switching by incumbent; baseline condition is NRM-aligned (ruling party) voter",
          df = FALSE, omit.stat = c("rsq","ser"),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Thu, Dec 07, 2017 - 17:32:36


######################################################################################
###Table S13: Conditional effects of budget treatment based on the alignment of the voter and the incumbent
######################################################################################

h1a.b.1c.aligned <- felm(lc5.chair.inc.vote ~ budget.treat*aligned.lc5.chair.inc.noNA + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2c.aligned <- felm(lc5.councillor.inc.vote ~ budget.treat*aligned.lc5.councillor.inc.noNA + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1c.aligned <- felm(lc5.chair.inc.vote ~ budget.treat*aligned.lc5.chair.inc.noNA + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2c.aligned <- felm(lc5.councillor.inc.vote ~ budget.treat*aligned.lc5.councillor.inc.noNA + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)

stargazer(h1a.b.1c.aligned, h1a.b.2c.aligned, h1b.b.1c.aligned, h1b.b.2c.aligned, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(2,2),
          keep = c("budget.treat","aligned.lc5.chair.inc.noNA","aligned.lc5.councillor.inc.noNA"),
          covariate.labels = c("Budget Treatment","Aligned","Alignment Unknown","Aligned","Alignment Unknown","Budget Treatment * Aligned","Budget Treatment * Alignment Unknown","Budget Treatment * Aligned","Budget Treatment * Alignment Unknown"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes"),
                           c("Covariates", "Yes", "Yes","Yes","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          notes = "Notes: SEs clustered by politician; two-tailed tests; contested elections only without party switching by incumbent; baseline condition is not aligned incumbent and voter.",
          df = FALSE, omit.stat = c("rsq","ser"),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Thu, Dec 07, 2017 - 18:14:43
#Note: have to rearrange table to combine chair / councillor interaction terms


######################################################################################
###Table S14: Results on vote choice for primary specification (main effects)
######################################################################################

#Duplicate of "Main Effects" section in the "Figure 1" block in BJNP_PNAS_replication.R
###Budget / LC5 chair results
chair.good <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name,
                      dta=budget.good.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                      rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.bad <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, 
                     dta=budget.bad.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                     rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.good.cov <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name,
                          dta=budget.good.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.bad.cov <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                         dta=budget.bad.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                         rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

###Budget / LC5 councillor results
coun.good <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name,
                     dta=budget.good.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                     rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.bad <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, 
                    dta=budget.bad.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                    rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.good.cov <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name,
                         dta=budget.good.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                         rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.bad.cov <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                        dta=budget.bad.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)


h1a.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)
h1a.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)

stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          covariate.labels = c("Budget Treatment (RI)","LC5 Chair Intent","Living Conditions: Don't Know","Living Conditions: Missing","Living Conditions: Much Better","Living Conditions: Much Worse","Living Conditions: Refused","Living Conditions: Same", "Living Conditions: Worse", "Trust in Twaweza: Don't Know", "Trust in Twaweza: Missing", "Trust in Twaweza: A Little", "Trust in Twaweza: A Lot", "Voting Not Secret: Missing", "Voting Not Secret: Not At All Likely", "Voting Not Secret: Not Very Likely", "Voting Not Secret: Refused", "Voting Not Secret: Somewhat Likely", "Voting Not Secret: Very Likely", "Fair Vote Counting: Missing", "Fair Vote Counting: Not At All Likely", "Fair Vote Counting: Not Very Likely", "Fair Vote Counting: Refused", "Fair Vote Counting: Somewhat Likely", "Fair Vote Counting: Very Likely", "Male", "Education: Some Primary", "Education: Completed Primary", "Education: Some Secondary", "Education: Completed Secondary", "Education: Some University", "Education: Completed University", "Education: Some Post-Graduate", "Education: Completed Masters", "Education: Refused", "Age", "LC5 Councillor Intent"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          notes = "Notes: SEs derived from randomization inference for treatment and clustered by politician for all other covariates; one-tailed tests on treatment as pre-registered; contested elections where incumbent did not switch parties only.",
          df = FALSE, omit.stat = c("rsq","ser"),
          se = list(c(chair.good$se,as.numeric(h1a.b.1$cse[2:length(h1a.b.1$cse)])),
                    c(chair.good.cov$se,as.numeric(h1a.b.1c$cse[2:length(h1a.b.1c$cse)])),
                    c(coun.good$se,as.numeric(h1a.b.2$cse[2:length(h1a.b.2$cse)])),
                    c(coun.good.cov$se,as.numeric(h1a.b.2c$cse[2:length(h1a.b.2c$cse)])),
                    c(chair.bad$se,as.numeric(h1b.b.1$cse[2:length(h1b.b.1$cse)])),
                    c(chair.bad.cov$se,as.numeric(h1b.b.1c$cse[2:length(h1b.b.1c$cse)])),
                    c(coun.bad$se,as.numeric(h1b.b.2$cse[2:length(h1b.b.2$cse)])),
                    c(coun.bad.cov$se,as.numeric(h1b.b.2c$cse[2:length(h1b.b.2c$cse)]))
          ),
          p = c(chair.good$p.one.way.greater,
                chair.good.cov$p.one.way.greater,
                coun.good$p.one.way.greater,
                coun.good.cov$p.one.way.greater,
                chair.bad$p.one.way.lesser,
                chair.bad.cov$p.one.way.lesser,
                coun.bad$p.one.way.lesser,
                coun.bad.cov$p.one.way.lesser),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Sun, Mar 18, 2018 - 08:58:59


######################################################################################
###Table S15: Results on vote choice for primary specification (verified recipient effects)
######################################################################################

#Duplicate of "Verified Recipient Effects" section in the "Figure 1" block in BJNP_PNAS_replication.R
###Budget / LC5 chair results, verified compliers
chair.good.c <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name,
                        dta=budget.good.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.bad.c <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, 
                       dta=budget.bad.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                       rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.good.cov.c <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name,
                            dta=budget.good.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                            rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.bad.cov.c <- felm.ri(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                           dta=budget.bad.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                           rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

###Budget / LC5 councillor results, verified compliers
coun.good.c <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name,
                       dta=budget.good.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                       rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.bad.c <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, 
                      dta=budget.bad.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                      rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.good.cov.c <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name,
                           dta=budget.good.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                           rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.bad.cov.c <- felm.ri(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                          dta=budget.bad.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

h1a.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp.c)
h1a.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp.c)
h1b.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp.c)
h1b.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp.c)
h1a.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp.c)
h1a.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp.c)
h1b.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp.c)
h1b.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp.c)

stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          covariate.labels = c("Budget Treatment (RI)","LC5 Chair Intent","Living Conditions: Don't Know","Living Conditions: Missing","Living Conditions: Much Better","Living Conditions: Much Worse","Living Conditions: Refused","Living Conditions: Same", "Living Conditions: Worse", "Trust in Twaweza: Don't Know", "Trust in Twaweza: Missing", "Trust in Twaweza: A Little", "Trust in Twaweza: A Lot", "Voting Not Secret: Missing", "Voting Not Secret: Not At All Likely", "Voting Not Secret: Not Very Likely", "Voting Not Secret: Refused", "Voting Not Secret: Somewhat Likely", "Voting Not Secret: Very Likely", "Fair Vote Counting: Missing", "Fair Vote Counting: Not At All Likely", "Fair Vote Counting: Not Very Likely", "Fair Vote Counting: Refused", "Fair Vote Counting: Somewhat Likely", "Fair Vote Counting: Very Likely", "Male", "Education: Some Primary", "Education: Completed Primary", "Education: Some Secondary", "Education: Completed Secondary", "Education: Some University", "Education: Completed University", "Education: Some Post-Graduate", "Education: Completed Masters", "Education: Refused", "Age", "LC5 Councillor Intent"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          notes = "Notes: SEs derived from randomization inference for treatment and clustered by politician for all other covariates; one-tailed tests on treatment as pre-registered; contested elections where incumbent did not switch parties only.",
          df = FALSE, omit.stat = c("rsq","ser"),
          se = list(c(chair.good.c$se,as.numeric(h1a.b.1$cse[2:length(h1a.b.1$cse)])),
                    c(chair.good.cov.c$se,as.numeric(h1a.b.1c$cse[2:length(h1a.b.1c$cse)])),
                    c(coun.good.c$se,as.numeric(h1a.b.2$cse[2:length(h1a.b.2$cse)])),
                    c(coun.good.cov.c$se,as.numeric(h1a.b.2c$cse[2:length(h1a.b.2c$cse)])),
                    c(chair.bad.c$se,as.numeric(h1b.b.1$cse[2:length(h1b.b.1$cse)])),
                    c(chair.bad.cov.c$se,as.numeric(h1b.b.1c$cse[2:length(h1b.b.1c$cse)])),
                    c(coun.bad.c$se,as.numeric(h1b.b.2$cse[2:length(h1b.b.2$cse)])),
                    c(coun.bad.cov.c$se,as.numeric(h1b.b.2c$cse[2:length(h1b.b.2c$cse)]))
          ),
          p = c(chair.good.c$p.one.way.greater,
                chair.good.cov.c$p.one.way.greater,
                coun.good.c$p.one.way.greater,
                coun.good.cov.c$p.one.way.greater,
                chair.bad.c$p.one.way.lesser,
                chair.bad.cov.c$p.one.way.lesser,
                coun.bad.c$p.one.way.lesser,
                coun.bad.cov.c$p.one.way.lesser),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Sun, Mar 18, 2018 - 11:13:02


######################################################################################
###Table S16: Effect of budget treatment on votes for district (LC V) incumbents, estimated as pre-specified
######################################################################################

h1a.b.1 <- felm(lc5.chair.transformed ~ budget.treat | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2 <- felm(lc5.councillor.transformed ~ budget.treat | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1 <- felm(lc5.chair.transformed ~ budget.treat | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2 <- felm(lc5.councillor.transformed ~ budget.treat | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)
h1a.b.1c <- felm(lc5.chair.transformed ~ budget.treat + b.Q1_living_conditions + b.Q6_vote_for_current_LC5chair + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h1a.b.2c <- felm(lc5.councillor.transformed ~ budget.treat + b.Q1_living_conditions + b.Q5_vote_for_current_LC5council + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h1b.b.1c <- felm(lc5.chair.transformed ~ budget.treat + b.Q1_living_conditions + b.Q6_vote_for_current_LC5chair + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h1b.b.2c <- felm(lc5.councillor.transformed ~ budget.treat + b.Q1_living_conditions + b.Q5_vote_for_current_LC5council + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)

t.chair.good <- felm.ri(lc5.chair.transformed ~ budget.treat | location.id | 0 | lc5.chair.name,
                        dta=budget.good.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

t.chair.bad <- felm.ri(lc5.chair.transformed ~ budget.treat | location.id | 0 | lc5.chair.name, 
                       dta=budget.bad.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                       rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

t.chair.good.cov <- felm.ri(lc5.chair.transformed ~ budget.treat + b.Q1_living_conditions + b.Q6_vote_for_current_LC5chair + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name,
                            dta=budget.good.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                            rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

t.chair.bad.cov <- felm.ri(lc5.chair.transformed ~ budget.treat + b.Q1_living_conditions + b.Q6_vote_for_current_LC5chair + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                           dta=budget.bad.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                           rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

t.coun.good <- felm.ri(lc5.councillor.transformed ~ budget.treat | location.id | 0 | lc5.councillor.name,
                       dta=budget.good.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                       rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

t.coun.bad <- felm.ri(lc5.councillor.transformed ~ budget.treat | location.id | 0 | lc5.councillor.name, 
                      dta=budget.bad.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                      rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

t.coun.good.cov <- felm.ri(lc5.councillor.transformed ~ budget.treat + b.Q1_living_conditions + b.Q5_vote_for_current_LC5council + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name,
                           dta=budget.good.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                           rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

t.coun.bad.cov <- felm.ri(lc5.councillor.transformed ~ budget.treat + b.Q1_living_conditions + b.Q5_vote_for_current_LC5council + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                          dta=budget.bad.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          keep = c("budget.treat"),
          covariate.labels = c("Budget Treatment (RI)"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates","No","Yes","No","Yes","No","Yes","No","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          notes = "Notes: SEs derived from randomization inference for treatment and clustered by politician for all other covariates; one-tailed tests on treatment as pre-registered; contested elections where incumbent did not switch parties only.",
          df = FALSE, omit.stat = c("rsq","ser"),
          se = list(c(t.chair.good$se),
                    c(t.chair.good.cov$se),
                    c(t.coun.good$se),
                    c(t.coun.good.cov$se),
                    c(t.chair.bad$se),
                    c(t.chair.bad.cov$se),
                    c(t.coun.bad$se),
                    c(t.coun.bad.cov$se)
          ),
          p = c(t.chair.good$p.one.way.greater,
                t.chair.good.cov$p.one.way.greater,
                t.coun.good$p.one.way.greater,
                t.coun.good.cov$p.one.way.greater,
                t.chair.bad$p.one.way.lesser,
                t.chair.bad.cov$p.one.way.lesser,
                t.coun.bad$p.one.way.lesser,
                t.coun.bad.cov$p.one.way.lesser),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Fri, Dec 08, 2017 - 07:46:55


######################################################################################
###Table S17: Effect of budget treatment and treatment density on vote choice for district (LCV) incumbents, estimated as pre-specified
######################################################################################

b.ri <- data.matrix(Budget_RI)
d.ri <- data.matrix(Density_RI)
#Note: NAs introduced by coercion warning generated because "district" and "village" variables cannot be made numeric
#Note: these NAs are excluded when only the treatment variables are pasted into the final "BD_RI" dataframe in the block below

BD_RI <- matrix(paste(b.ri,d.ri,sep="."),nrow=16083,ncol=10003)
BD_RI[BD_RI=="0.NA" | BD_RI=="1.NA"] <- NA
BD_RI[BD_RI=="0. 0"] <- "0.0"
BD_RI[BD_RI=="0. 1"] <- "0.1"
BD_RI[BD_RI=="1. 0"] <- "1.0"
BD_RI[BD_RI=="1. 1"] <- "1.1"
BD_RI <- as.data.frame(BD_RI)
BD_RI <- cbind(Budget_RI[,1:3],BD_RI[,4:ncol(BD_RI)])
remove(b.ri,d.ri)

h11a.b.1 <- felm(lc5.chair.transformed ~ bd.multi.treat + b.Q6_vote_for_current_LC5chair  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.chair.name, data=budget.good.lc5.chair.comp)
h11a.b.2 <- felm(lc5.councillor.transformed ~ bd.multi.treat + b.Q5_vote_for_current_LC5council  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.councillor.name, data=budget.good.lc5.councillor.comp)
h11b.b.1 <- felm(lc5.chair.transformed ~ bd.multi.treat + b.Q6_vote_for_current_LC5chair  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.chair.name, data=budget.bad.lc5.chair.comp)
h11b.b.2 <- felm(lc5.councillor.transformed ~ bd.multi.treat + b.Q5_vote_for_current_LC5council  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.councillor.name, data=budget.bad.lc5.councillor.comp)

chair.good.crossed.pap <- felm.ri2(lc5.chair.transformed ~ bd.multi.treat2 + b.Q6_vote_for_current_LC5chair  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.chair.name,
                                   dta=budget.good.lc5.chair.comp, treat.var = "bd.multi.treat2", rand.ob=BD_RI,
                                   rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.good.crossed.pap <- felm.ri2(lc5.councillor.transformed ~ bd.multi.treat2 + b.Q5_vote_for_current_LC5council  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.councillor.name, 
                                  dta=budget.good.lc5.councillor.comp, treat.var = "bd.multi.treat2", rand.ob=BD_RI,
                                  rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

chair.bad.crossed.pap <- felm.ri2(lc5.chair.transformed ~ bd.multi.treat2 + b.Q6_vote_for_current_LC5chair  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.chair.name,
                                  dta=budget.bad.lc5.chair.comp, treat.var = "bd.multi.treat2", rand.ob=BD_RI,
                                  rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

coun.bad.crossed.pap <- felm.ri2(lc5.councillor.transformed ~ bd.multi.treat2 + b.Q5_vote_for_current_LC5council  + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | d.block | 0 | lc5.councillor.name, 
                                 dta=budget.bad.lc5.councillor.comp, treat.var = "bd.multi.treat2", rand.ob=BD_RI,
                                 rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999)

stargazer(h11a.b.1, h11a.b.2, h11b.b.1, h11b.b.2, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(2,2),
          keep = c("bd.multi.treatbudget0.density1","bd.multi.treatbudget1.density0","bd.multi.treatbudget1.density1"),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Control, High Density (RI)","Treated, Low Density (RI)", "Treated, High Density (RI)"),
          notes = "Notes: SEs derived from RI; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          se = list(chair.good.crossed.pap$se,coun.good.crossed.pap$se,chair.bad.crossed.pap$se,coun.bad.crossed.pap$se),
          p = list(chair.good.crossed.pap$p.one.way.greater, coun.good.crossed.pap$p.one.way.greater, chair.bad.crossed.pap$p.one.way.lesser, coun.bad.crossed.pap$p.one.way.lesser),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Sat, Dec 09, 2017 - 12:32:30


######################################################################################
###Table S18: Conditional effects of budget treatment on votes for incumbents based on party switching
######################################################################################

h1a.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat*lc5.chair.party.switch + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.good, lc5.chair.competitive==1))
p1 <- ifelse(h1a.b.1$coef[1]>0, summary(h1a.b.1)$coef[1,4]/2, 1-summary(h1a.b.1)$coef[1,4]/2)

h1a.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat*lc5.councillor.party.switch + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.good, lc5.councillor.competitive==1))
p2 <- ifelse(h1a.b.2$coef[1]>0, summary(h1a.b.2)$coef[1,4]/2, 1-summary(h1a.b.2)$coef[1,4]/2)

h1b.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat*lc5.chair.party.switch + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.bad, lc5.chair.competitive==1))
p3 <- ifelse(h1b.b.1$coef[1]<0, summary(h1b.b.1)$coef[1,4]/2, 1-summary(h1b.b.1)$coef[1,4]/2)

h1b.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat*lc5.councillor.party.switch + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.bad, lc5.councillor.competitive==1))
p4 <- ifelse(h1b.b.2$coef[1]<0, summary(h1b.b.2)$coef[1,4]/2, 1-summary(h1b.b.2)$coef[1,4]/2)

h1a.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat*lc5.chair.party.switch + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.good, lc5.chair.competitive==1))
p5 <- ifelse(h1a.b.1c$coef[1]>0, summary(h1a.b.1c)$coef[1,4]/2, 1-summary(h1a.b.1c)$coef[1,4]/2)

h1a.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat*lc5.councillor.party.switch + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.good, lc5.councillor.competitive==1))
p6 <- ifelse(h1a.b.2c$coef[1]>0, summary(h1a.b.2c)$coef[1,4]/2, 1-summary(h1a.b.2c)$coef[1,4]/2)

h1b.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat*lc5.chair.party.switch + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.bad, lc5.chair.competitive==1))
p7 <- ifelse(h1b.b.1c$coef[1]<0, summary(h1b.b.1c)$coef[1,4]/2, 1-summary(h1b.b.1c)$coef[1,4]/2)

h1b.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat*lc5.councillor.party.switch + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.bad, lc5.councillor.competitive==1))
p8 <- ifelse(h1b.b.2c$coef[1]<0, summary(h1b.b.2c)$coef[1,4]/2, 1-summary(h1b.b.2c)$coef[1,4]/2)

stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          keep = c("budget.treat","lc5.chair.intent","lc5.councillor.intent","budget.treat:lc5.chair.party.switch","budget.treat:lc5.councillor.party.switch"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates", "No","Yes","No","Yes","No","Yes","No","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Budget Treatment","LC5 Chair Intent","Budget Treatment X Chair Party Switch","LC5 Councillor Intent", "Budget Treatment X Councillor Party Switch"),
          notes = "Notes: SEs clustered by politician; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          p = list(p1,p5,p2,p6,p3,p7,p4,p8),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Tue, Mar 13, 2018 - 16:00:04


######################################################################################
###Table S19: Effects of budget treatment on votes for individual incumbents who ran for re-election as members of the same party
######################################################################################

h1a.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.good.lc5.chair.comp, lc5.chair.ran2016==TRUE))
p1 <- ifelse(h1a.b.1$coef[1]>0, summary(h1a.b.1)$coef[1,4]/2, 1-summary(h1a.b.1)$coef[1,4]/2)

h1a.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.good.lc5.councillor.comp, lc5.councillor.ran2016==TRUE))
p2 <- ifelse(h1a.b.2$coef[1]>0, summary(h1a.b.2)$coef[1,4]/2, 1-summary(h1a.b.2)$coef[1,4]/2)

h1b.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.bad.lc5.chair.comp, lc5.chair.ran2016==TRUE))
p3 <- ifelse(h1b.b.1$coef[1]<0, summary(h1b.b.1)$coef[1,4]/2, 1-summary(h1b.b.1)$coef[1,4]/2)

h1b.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.bad.lc5.councillor.comp, lc5.councillor.ran2016==TRUE))
p4 <- ifelse(h1b.b.2$coef[1]<0, summary(h1b.b.2)$coef[1,4]/2, 1-summary(h1b.b.2)$coef[1,4]/2)

h1a.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.good.lc5.chair.comp, lc5.chair.ran2016==TRUE))
p5 <- ifelse(h1a.b.1c$coef[1]>0, summary(h1a.b.1c)$coef[1,4]/2, 1-summary(h1a.b.1c)$coef[1,4]/2)

h1a.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.good.lc5.councillor.comp, lc5.councillor.ran2016==TRUE))
p6 <- ifelse(h1a.b.2c$coef[1]>0, summary(h1a.b.2c)$coef[1,4]/2, 1-summary(h1a.b.2c)$coef[1,4]/2)

h1b.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.bad.lc5.chair.comp, lc5.chair.ran2016==TRUE))
p7 <- ifelse(h1b.b.1c$coef[1]<0, summary(h1b.b.1c)$coef[1,4]/2, 1-summary(h1b.b.1c)$coef[1,4]/2)

h1b.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.bad.lc5.councillor.comp, lc5.councillor.ran2016==TRUE))
p8 <- ifelse(h1b.b.2c$coef[1]<0, summary(h1b.b.2c)$coef[1,4]/2, 1-summary(h1b.b.2c)$coef[1,4]/2)

stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          keep = c("budget.treat","lc5.chair.intent","lc5.councillor.intent"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates", "No","Yes","No","Yes","No","Yes","No","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Budget Treatment","LC5 Chair Intent","LC5 Councillor Intent"),
          notes = "Notes: SEs clustered by politician; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          p = list(p1,p5,p2,p6,p3,p7,p4,p8),
          se = list(h1a.b.1$cse[1:2],
                    h1a.b.1c$cse[1:2],
                    h1a.b.2$cse[1:2],
                    h1a.b.2c$cse[1:2],
                    h1b.b.1$cse[1:2],
                    h1b.b.1c$cse[1:2],
                    h1b.b.2$cse[1:2],
                    h1b.b.2c$cse[1:2]),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Sat, Dec 09, 2017 - 09:38:56


######################################################################################
###Table S20: Effects of budget treatment on votes for district incumbents, with incumbency defined as the party previously elected to the seat
######################################################################################

h1a.b.1 <- felm(lc5.chair.inc.vote.orig ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.good, lc5.chair.competitive==1))
p1 <- ifelse(h1a.b.1$coef[1]>0, summary(h1a.b.1)$coef[1,4]/2, 1-summary(h1a.b.1)$coef[1,4]/2)

h1a.b.2 <- felm(lc5.councillor.inc.vote.orig ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.good, lc5.councillor.competitive==1  & is.na(lc5.councillor.redistricted2016)))
p2 <- ifelse(h1a.b.2$coef[1]>0, summary(h1a.b.2)$coef[1,4]/2, 1-summary(h1a.b.2)$coef[1,4]/2)

h1b.b.1 <- felm(lc5.chair.inc.vote.orig ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.bad, lc5.chair.competitive==1))
p3 <- ifelse(h1b.b.1$coef[1]<0, summary(h1b.b.1)$coef[1,4]/2, 1-summary(h1b.b.1)$coef[1,4]/2)

h1b.b.2 <- felm(lc5.councillor.inc.vote.orig ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.bad, lc5.councillor.competitive==1  & is.na(lc5.councillor.redistricted2016)))
p4 <- ifelse(h1b.b.2$coef[1]<0, summary(h1b.b.2)$coef[1,4]/2, 1-summary(h1b.b.2)$coef[1,4]/2)

h1a.b.1c <- felm(lc5.chair.inc.vote.orig ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.good, lc5.chair.competitive==1))
p5 <- ifelse(h1a.b.1c$coef[1]>0, summary(h1a.b.1c)$coef[1,4]/2, 1-summary(h1a.b.1c)$coef[1,4]/2)

h1a.b.2c <- felm(lc5.councillor.inc.vote.orig ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.good, lc5.councillor.competitive==1 & is.na(lc5.councillor.redistricted2016)))
p6 <- ifelse(h1a.b.2c$coef[1]>0, summary(h1a.b.2c)$coef[1,4]/2, 1-summary(h1a.b.2c)$coef[1,4]/2)

h1b.b.1c <- felm(lc5.chair.inc.vote.orig ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.bad, lc5.chair.competitive==1))
p7 <- ifelse(h1b.b.1c$coef[1]<0, summary(h1b.b.1c)$coef[1,4]/2, 1-summary(h1b.b.1c)$coef[1,4]/2)

h1b.b.2c <- felm(lc5.councillor.inc.vote.orig ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.bad, lc5.councillor.competitive==1 & is.na(lc5.councillor.redistricted2016)))
p8 <- ifelse(h1b.b.2c$coef[1]<0, summary(h1b.b.2c)$coef[1,4]/2, 1-summary(h1b.b.2c)$coef[1,4]/2)

stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          keep = c("budget.treat","lc5.chair.intent","lc5.councillor.intent"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates", "No","Yes","No","Yes","No","Yes","No","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Budget Treatment","LC5 Chair Intent","LC5 Councillor Intent"),
          notes = "Notes: SEs clustered by politician; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          p = list(p1,p5,p2,p6,p3,p7,p4,p8),
          se = list(h1a.b.1$cse[1:2],
                    h1a.b.1c$cse[1:2],
                    h1a.b.2$cse[1:2],
                    h1a.b.2c$cse[1:2],
                    h1b.b.1$cse[1:2],
                    h1b.b.1c$cse[1:2],
                    h1b.b.2$cse[1:2],
                    h1b.b.2c$cse[1:2]),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) #Date and time: Sat, Dec 09, 2017 - 09:51:49


######################################################################################
###Table S21: Effects of budget treatment on votes for district incumbents, with incumbency defined by individual if the individual is running for re-election
######################################################################################

#Note: this is the same as Table S18 without the interaction term for party switching

h1a.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.good, lc5.chair.competitive==1))
p1 <- ifelse(h1a.b.1$coef[1]>0, summary(h1a.b.1)$coef[1,4]/2, 1-summary(h1a.b.1)$coef[1,4]/2)

h1a.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.good, lc5.councillor.competitive==1))
p2 <- ifelse(h1a.b.2$coef[1]>0, summary(h1a.b.2)$coef[1,4]/2, 1-summary(h1a.b.2)$coef[1,4]/2)

h1b.b.1 <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, data=filter(budget.bad, lc5.chair.competitive==1))
p3 <- ifelse(h1b.b.1$coef[1]<0, summary(h1b.b.1)$coef[1,4]/2, 1-summary(h1b.b.1)$coef[1,4]/2)

h1b.b.2 <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, data=filter(budget.bad, lc5.councillor.competitive==1))
p4 <- ifelse(h1b.b.2$coef[1]<0, summary(h1b.b.2)$coef[1,4]/2, 1-summary(h1b.b.2)$coef[1,4]/2)

h1a.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.good, lc5.chair.competitive==1))
p5 <- ifelse(h1a.b.1c$coef[1]>0, summary(h1a.b.1c)$coef[1,4]/2, 1-summary(h1a.b.1c)$coef[1,4]/2)

h1a.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.good, lc5.councillor.competitive==1))
p6 <- ifelse(h1a.b.2c$coef[1]>0, summary(h1a.b.2c)$coef[1,4]/2, 1-summary(h1a.b.2c)$coef[1,4]/2)

h1b.b.1c <- felm(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, data=filter(budget.bad, lc5.chair.competitive==1))
p7 <- ifelse(h1b.b.1c$coef[1]<0, summary(h1b.b.1c)$coef[1,4]/2, 1-summary(h1b.b.1c)$coef[1,4]/2)

h1b.b.2c <- felm(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, data=filter(budget.bad, lc5.councillor.competitive==1))
p8 <- ifelse(h1b.b.2c$coef[1]<0, summary(h1b.b.2c)$coef[1,4]/2, 1-summary(h1b.b.2c)$coef[1,4]/2)

stargazer(h1a.b.1, h1a.b.1c, h1a.b.2, h1a.b.2c, h1b.b.1, h1b.b.1c, h1b.b.2, h1b.b.2c, type = "latex", 
          dep.var.labels = c("LC5 Chair", "LC5 Councillor", "LC5 Chair", "LC5 Councillor"),
          column.labels = c("Good News","Bad News"), column.separate = c(4,4),
          keep = c("budget.treat","lc5.chair.intent","lc5.councillor.intent"),
          add.lines = list(c("Village fixed effects", "Yes", "Yes","Yes","Yes","Yes", "Yes","Yes","Yes"),
                           c("Covariates", "No","Yes","No","Yes","No","Yes","No","Yes")),
          dep.var.caption  = "DV: Vote Choice for the Incumbent",
          covariate.labels = c("Budget Treatment","LC5 Chair Intent","LC5 Councillor Intent"),
          notes = "Notes: SEs clustered by politician; one-tailed tests as pre-registered; contested elections only",
          df = FALSE, omit.stat = c("rsq","ser"),
          p = list(p1,p5,p2,p6,p3,p7,p4,p8),
          se = list(h1a.b.1$cse[1:2],
                    h1a.b.1c$cse[1:2],
                    h1a.b.2$cse[1:2],
                    h1a.b.2c$cse[1:2],
                    h1b.b.1$cse[1:2],
                    h1b.b.1c$cse[1:2],
                    h1b.b.2$cse[1:2],
                    h1b.b.2c$cse[1:2]),
          report = c('vcsp'),
          notes.append = FALSE,
          notes.label = ""
) # Date and time: Sat, Dec 09, 2017 - 10:16:04


######################################################################################
###Table S23: Manipulation checks for updating in beliefs about budget performance of LC V
######################################################################################

data$manipulation.updating.loose <- ifelse(data$budget.post.diff==0 | abs(data$budget.post.diff) <= abs(data$budget.prior.diff), 1, 0)
data$directional.updating <- ifelse(data$budget.post.diff==0 & data$budget.prior.diff==0, 1, 0)
data$directional.updating <- ifelse(data$budget.prior.diff>0 & data$budget.post > data$budget.prior, 1, data$directional.updating)
data$directional.updating <- ifelse(data$budget.prior.diff<0 & data$budget.post < data$budget.prior, 1, data$directional.updating)
data$directional.updating <- ifelse(is.na(data$budget.prior) | is.na(data$budget.post), NA, data$directional.updating)

##Strict updating
strict <- felm(manipulation.strict ~ budget.treat |0|0|0, data=data)
summary(strict)

strict.fe <- felm(manipulation.strict ~ budget.treat |location.id|0|0, data=data)
summary(strict.fe)

strict.fe.c <- felm(manipulation.strict ~ budget.treat |location.id|0|district_lower, data=data)
summary(strict.fe.c)

##Updating
updating <- felm(manipulation.updating ~ budget.treat |0|0|0, data=data)
summary(updating)

updating.fe <- felm(manipulation.updating ~ budget.treat |location.id|0|0, data=data)
summary(updating.fe)

updating.fe.c <- felm(manipulation.updating ~ budget.treat |location.id|0|district_lower, data=data)
summary(updating.fe.c)

##Loose updating
loose <- felm(manipulation.updating.loose ~ budget.treat |0|0|0, data=data)
summary(loose)

loose.fe <- felm(manipulation.updating.loose ~ budget.treat |location.id|0|0, data=data)
summary(loose.fe)

loose.fe.c <- felm(manipulation.updating.loose ~ budget.treat |location.id|0|district_lower, data=data)
summary(loose.fe.c)

#Accounting for eligibility for divergence
data$diverge.eligble <- 1
data$diverge.eligble <- ifelse(data$budget.prior==1 & data$budget.actual>=4, 0, data$diverge.eligble)
data$diverge.eligble <- ifelse(data$budget.prior==5 & data$budget.actual<=2, 0, data$diverge.eligble)
table(data$diverge.eligble)

loose.e <- felm(manipulation.updating.loose ~ budget.treat |0|0|0, data=filter(data, diverge.eligble==1))
summary(loose.e)

loose.e.fe <- felm(manipulation.updating.loose ~ budget.treat |location.id|0|0, data=filter(data, diverge.eligble==1))
summary(loose.e.fe)

loose.e.fe.c <- felm(manipulation.updating.loose ~ budget.treat |location.id|0|district_lower, data=filter(data, diverge.eligble==1))
summary(loose.e.fe.c)

##Directional updating
directional <- felm(directional.updating ~ budget.treat |0|0|0, data=data)
summary(directional)

directional.fe <- felm(directional.updating ~ budget.treat |location.id|0|0, data=data)
summary(directional.fe)

directional.fe.c <- felm(directional.updating ~ budget.treat |location.id|0|district_lower, data=data)
summary(directional.fe.c)

##Table harvesting
strict.coef <- c(summary(strict)$coefficient[2,1],summary(strict.fe)$coefficient[1,1],summary(strict.fe.c)$coefficient[1,1])
strict.se <- c(summary(strict)$coefficient[2,2],summary(strict.fe)$coefficient[1,2],summary(strict.fe.c)$coefficient[1,2])
strict.p <- c(summary(strict)$coefficient[2,4],summary(strict.fe)$coefficient[1,4],summary(strict.fe.c)$coefficient[1,4])
strict.p.one.side <- strict.p/2

updating.coef <- c(summary(updating)$coefficient[2,1],summary(updating.fe)$coefficient[1,1],summary(updating.fe.c)$coefficient[1,1])
updating.se <- c(summary(updating)$coefficient[2,2],summary(updating.fe)$coefficient[1,2],summary(updating.fe.c)$coefficient[1,2])
updating.p <- c(summary(updating)$coefficient[2,4],summary(updating.fe)$coefficient[1,4],summary(updating.fe.c)$coefficient[1,4])
updating.p.one.side <- updating.p/2

loose.coef <- c(summary(loose)$coefficient[2,1],summary(loose.fe)$coefficient[1,1],summary(loose.fe.c)$coefficient[1,1])
loose.se <- c(summary(loose)$coefficient[2,2],summary(loose.fe)$coefficient[1,2],summary(loose.fe.c)$coefficient[1,2])
loose.p <- c(summary(loose)$coefficient[2,4],summary(loose.fe)$coefficient[1,4],summary(loose.fe.c)$coefficient[1,4])
loose.p.one.side <- loose.p/2

loose.e.coef <- c(summary(loose.e)$coefficient[2,1],summary(loose.e.fe)$coefficient[1,1],summary(loose.e.fe.c)$coefficient[1,1])
loose.e.se <- c(summary(loose.e)$coefficient[2,2],summary(loose.e.fe)$coefficient[1,2],summary(loose.e.fe.c)$coefficient[1,2])
loose.e.p <- c(summary(loose.e)$coefficient[2,4],summary(loose.e.fe)$coefficient[1,4],summary(loose.e.fe.c)$coefficient[1,4])
loose.e.p.one.side <- loose.e.p/2

directional.coef <- c(summary(directional)$coefficient[2,1],summary(directional.fe)$coefficient[1,1],summary(directional.fe.c)$coefficient[1,1])
directional.se <- c(summary(directional)$coefficient[2,2],summary(directional.fe)$coefficient[1,2],summary(directional.fe.c)$coefficient[1,2])
directional.p <- c(summary(directional)$coefficient[2,4],summary(directional.fe)$coefficient[1,4],summary(directional.fe.c)$coefficient[1,4])
directional.p.one.side <- directional.p/2

#Formatting functions
coef.print <- function(vector){
  sprintf("%.3f",round(vector,3))
}

se.print <- function(vector){
  paste("(",sprintf("%.3f",round(vector,3)),")",sep="")
}

p.print <- function(vector){
  paste("p=",sprintf("%.3f", round(vector,3)),sep="")
}

tab.dta <- rbind(coef.print(strict.coef),se.print(strict.se),p.print(strict.p.one.side),
                 coef.print(updating.coef),se.print(updating.se),p.print(updating.p.one.side),
                 coef.print(loose.coef),se.print(loose.se),p.print(loose.p.one.side),
                 coef.print(loose.e.coef),se.print(loose.e.se),p.print(loose.e.p.one.side),
                 coef.print(directional.coef),se.print(directional.se),p.print(directional.p.one.side))
stargazer(tab.dta) #Mon, Mar 19, 2018 - 08:51:44
#Note: some post-formatting in LaTex necessary


######################################################################################
###Table S24: Multiple, joint, and pooled hypothesis tests using randomization inference
######################################################################################

#Run the "Figure 1" block in BJNP_PNAS_replication.R

##Creating pooled datasets
budget.good.lc5.chair.comp$inc.vote <- budget.good.lc5.chair.comp$lc5.chair.inc.vote
budget.good.lc5.chair.comp$intent <- budget.good.lc5.chair.comp$lc5.chair.intent
budget.good.lc5.councillor.comp$inc.vote <- budget.good.lc5.councillor.comp$lc5.councillor.inc.vote
budget.good.lc5.councillor.comp$intent <- budget.good.lc5.councillor.comp$lc5.councillor.intent

budget.good.lc5.chair.comp$id.cleaned2 <- budget.good.lc5.chair.comp$id.cleaned
budget.good.lc5.councillor.comp$id.cleaned2 <- budget.good.lc5.councillor.comp$id.cleaned + 100000
budget.good.both <- rbind(budget.good.lc5.chair.comp, budget.good.lc5.councillor.comp)

budget.bad.lc5.chair.comp$inc.vote <- budget.bad.lc5.chair.comp$lc5.chair.inc.vote
budget.bad.lc5.chair.comp$intent <- budget.bad.lc5.chair.comp$lc5.chair.intent
budget.bad.lc5.councillor.comp$inc.vote <- budget.bad.lc5.councillor.comp$lc5.councillor.inc.vote
budget.bad.lc5.councillor.comp$intent <- budget.bad.lc5.councillor.comp$lc5.councillor.intent

budget.bad.lc5.chair.comp$id.cleaned2 <- budget.bad.lc5.chair.comp$id.cleaned
budget.bad.lc5.councillor.comp$id.cleaned2 <- budget.bad.lc5.councillor.comp$id.cleaned + 100000
budget.bad.both <- rbind(budget.bad.lc5.chair.comp, budget.bad.lc5.councillor.comp)

Budget_RI$id.cleaned2 <- Budget_RI$id.cleaned
Budget_RI2 <- Budget_RI
Budget_RI2$id.cleaned2 <- Budget_RI2$id.cleaned + 100000
Budget_RI_both <- rbind(Budget_RI,Budget_RI2)

##Analyzing pooled outcomes
both.good <- felm(inc.vote ~ budget.treat + intent | location.id | 0 | id.cleaned,
                  data=budget.good.both)
summary(both.good)

both.bad <- felm(inc.vote ~ budget.treat + intent | location.id | 0 | id.cleaned,
                 data=budget.bad.both)
summary(both.bad)

##Budget / Pooled results
both.good <- felm.ri(inc.vote ~ budget.treat + intent | location.id | 0 | id.cleaned,
                     dta=budget.good.both, treat.var = "budget.treat", rand.ob=Budget_RI_both, 
                     rand.ob.info.cols = 4, join.var = "id.cleaned2", sims=9999)

both.bad <- felm.ri(inc.vote ~ budget.treat + intent | location.id | 0 | id.cleaned, 
                    dta=budget.bad.both, treat.var = "budget.treat", rand.ob=Budget_RI_both, 
                    rand.ob.info.cols = 4, join.var = "id.cleaned2", sims=9999)

both.good.cov <- felm.ri(inc.vote ~ budget.treat + intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | id.cleaned,
                         dta=budget.good.both, treat.var = "budget.treat", rand.ob=Budget_RI_both, 
                         rand.ob.info.cols = 4, join.var = "id.cleaned2", sims=9999)

both.bad.cov <- felm.ri(inc.vote ~ budget.treat + intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | id.cleaned, 
                        dta=budget.bad.both, treat.var = "budget.treat", rand.ob=Budget_RI_both, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned2", sims=9999)

## Joint test of significance
sims <- 9999
ate.test.upper <- both.good$ate
ate.test.lower <- both.bad$ate

both.ate.upper.test <- both.good$ate.samp.dist > ate.test.upper
both.ate.lower.test <- both.bad$ate.samp.dist < ate.test.lower

joint.test <- both.ate.upper.test & both.ate.lower.test
p.both.joint <- sum(joint.test) / sims
p.both.joint #0.034

ate.test.upper <- both.good.cov$ate
ate.test.lower <- both.bad.cov$ate

both.ate.upper.test <- both.good.cov$ate.samp.dist > ate.test.upper
both.ate.lower.test <- both.bad.cov$ate.samp.dist < ate.test.lower

joint.test <- both.ate.upper.test & both.ate.lower.test
p.both.joint.cov <- sum(joint.test) / sims
p.both.joint.cov #0.030

#### Multiple hypothesis testing

sims <- 9999

### All subjects, no covariates

## Correction w/in good news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.good$ate,coun.good$ate)
ate.test <- max(ate.realized)

ate.chair.test <- chair.good$ate.samp.dist > ate.test
ate.coun.test <- coun.good$ate.samp.dist > ate.test

joint.test <- ate.chair.test | ate.coun.test
p.good.joint <- sum(joint.test) / sims
p.good.joint #0.111

## Correction w/in bad news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.bad$ate,coun.bad$ate)
ate.test <- min(ate.realized)

ate.chair.test <- chair.bad$ate.samp.dist < ate.test
ate.coun.test <- coun.bad$ate.samp.dist < ate.test

joint.test <- ate.chair.test | ate.coun.test
p.bad.joint <- sum(joint.test) / sims
p.bad.joint #0.030

## Joint test w/ chairs
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- chair.good$ate
ate.test.lower <- chair.bad$ate

ate.good.test <- chair.good$ate.samp.dist > ate.test.upper
ate.bad.test <- chair.bad$ate.samp.dist < ate.test.lower

joint.test <- ate.good.test & ate.bad.test
p.chair.joint <- sum(joint.test) / sims
p.chair.joint #0.343

## Joint test w/ councillors
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- coun.good$ate
ate.test.lower <- coun.bad$ate

ate.good.test <- coun.good$ate.samp.dist > ate.test.upper
ate.bad.test <- coun.bad$ate.samp.dist < ate.test.lower

joint.test <- ate.good.test & ate.bad.test
p.coun.joint <- sum(joint.test) / sims
p.coun.joint #0.001

## Joint test of all offices
#test: probability that at least one good news effect will exceed max good news effect & at least one bad news effect will exceed min bad news effect under the sharp null

ate.test.upper <- max(chair.good$ate,coun.good$ate)
ate.test.lower <- min(chair.bad$ate,coun.bad$ate)

chair.ate.good.test <- chair.good$ate.samp.dist > ate.test.upper
chair.ate.bad.test <- chair.bad$ate.samp.dist < ate.test.lower
coun.ate.good.test <- coun.good$ate.samp.dist > ate.test.upper
coun.ate.bad.test <- coun.bad$ate.samp.dist < ate.test.lower

joint.test <- (chair.ate.good.test | coun.ate.good.test) & (chair.ate.bad.test | coun.ate.bad.test)
p.joint <- sum(joint.test) / sims
p.joint #0.003

### All subjects, covariates

## Correction w/in good news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.good.cov$ate,coun.good.cov$ate)
ate.test <- max(ate.realized)

ate.chair.test <- chair.good.cov$ate.samp.dist > ate.test
ate.coun.test <- coun.good.cov$ate.samp.dist > ate.test

joint.test <- ate.chair.test | ate.coun.test
p.good.cov.joint <- sum(joint.test) / sims
p.good.cov.joint #0.103

## Correction w/in bad news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.bad.cov$ate,coun.bad.cov$ate)
ate.test <- min(ate.realized)

ate.chair.test <- chair.bad.cov$ate.samp.dist < ate.test
ate.coun.test <- coun.bad.cov$ate.samp.dist < ate.test

joint.test <- ate.chair.test | ate.coun.test
p.bad.cov.joint <- sum(joint.test) / sims
p.bad.cov.joint #0.025

## Joint test w/ chairs
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- chair.good.cov$ate
ate.test.lower <- chair.bad.cov$ate

ate.good.cov.test <- chair.good.cov$ate.samp.dist > ate.test.upper
ate.bad.cov.test <- chair.bad.cov$ate.samp.dist < ate.test.lower

joint.test <- ate.good.cov.test & ate.bad.cov.test
p.chair.cov.joint <- sum(joint.test) / sims
p.chair.cov.joint #0.327

## Joint test w/ councillors
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- coun.good.cov$ate
ate.test.lower <- coun.bad.cov$ate

ate.good.cov.test <- coun.good.cov$ate.samp.dist > ate.test.upper
ate.bad.cov.test <- coun.bad.cov$ate.samp.dist < ate.test.lower

joint.test <- ate.good.cov.test & ate.bad.cov.test
p.coun.cov.joint <- sum(joint.test) / sims
p.coun.cov.joint #0.001

## Joint test of all offices
#test: probability that at least one good news effect will exceed max good news effect & at least one bad news effect will exceed min bad news effect under the sharp null

ate.test.upper <- max(chair.good.cov$ate,coun.good.cov$ate)
ate.test.lower <- min(chair.bad.cov$ate,coun.bad.cov$ate)

chair.ate.good.cov.test <- chair.good.cov$ate.samp.dist > ate.test.upper
chair.ate.bad.cov.test <- chair.bad.cov$ate.samp.dist < ate.test.lower
coun.ate.good.cov.test <- coun.good.cov$ate.samp.dist > ate.test.upper
coun.ate.bad.cov.test <- coun.bad.cov$ate.samp.dist < ate.test.lower

joint.test <- (chair.ate.good.cov.test | coun.ate.good.cov.test) & (chair.ate.bad.cov.test | coun.ate.bad.cov.test)
p.joint.cov <- sum(joint.test) / sims
p.joint.cov #0.002

### Verified recipients, no covariates

## Correction w/in good.c news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.good.c$ate,coun.good.c$ate)
ate.test <- max(ate.realized)

ate.chair.test <- chair.good.c$ate.samp.dist > ate.test
ate.coun.test <- coun.good.c$ate.samp.dist > ate.test

joint.test <- ate.chair.test | ate.coun.test
p.good.c.joint <- sum(joint.test) / sims
p.good.c.joint #0.033

## Correction w/in bad.c news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.bad.c$ate,coun.bad.c$ate)
ate.test <- min(ate.realized)

ate.chair.test <- chair.bad.c$ate.samp.dist < ate.test
ate.coun.test <- coun.bad.c$ate.samp.dist < ate.test

joint.test <- ate.chair.test | ate.coun.test
p.bad.c.joint <- sum(joint.test) / sims
p.bad.c.joint #0.004

## Joint test w/ chairs
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- chair.good.c$ate
ate.test.lower <- chair.bad.c$ate

ate.good.c.test <- chair.good.c$ate.samp.dist > ate.test.upper
ate.bad.c.test <- chair.bad.c$ate.samp.dist < ate.test.lower

joint.test <- ate.good.c.test & ate.bad.c.test
p.chair.c.joint <- sum(joint.test) / sims
p.chair.c.joint #0.148

## Joint test w/ councillors
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- coun.good.c$ate
ate.test.lower <- coun.bad.c$ate

ate.good.c.test <- coun.good.c$ate.samp.dist > ate.test.upper
ate.bad.c.test <- coun.bad.c$ate.samp.dist < ate.test.lower

joint.test <- ate.good.c.test & ate.bad.c.test
p.coun.c.joint <- sum(joint.test) / sims
p.coun.c.joint #0.000

## Joint test of all offices
#test: probability that at least one good.c news effect will exceed max good.c news effect & at least one bad.c news effect will exceed min bad.c news effect under the sharp null

ate.test.upper <- max(chair.good.c$ate,coun.good.c$ate)
ate.test.lower <- min(chair.bad.c$ate,coun.bad.c$ate)

chair.ate.good.c.test <- chair.good.c$ate.samp.dist > ate.test.upper
chair.ate.bad.c.test <- chair.bad.c$ate.samp.dist < ate.test.lower
coun.ate.good.c.test <- coun.good.c$ate.samp.dist > ate.test.upper
coun.ate.bad.c.test <- coun.bad.c$ate.samp.dist < ate.test.lower

joint.test <- (chair.ate.good.c.test | coun.ate.good.c.test) & (chair.ate.bad.c.test | coun.ate.bad.c.test)
p.joint.c <- sum(joint.test) / sims
p.joint.c #0.000

### Verified recipients, covariates

## Correction w/in good news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.good.cov.c$ate,coun.good.cov.c$ate)
ate.test <- max(ate.realized)

ate.chair.test <- chair.good.cov.c$ate.samp.dist > ate.test
ate.coun.test <- coun.good.cov.c$ate.samp.dist > ate.test

joint.test <- ate.chair.test | ate.coun.test
p.good.cov.c.joint <- sum(joint.test) / sims
p.good.cov.c.joint #0.027

## Correction w/in bad news
#test: probability that at least one coefficient will be >= largest realized ATE

ate.realized <- c(chair.bad.cov.c$ate,coun.bad.cov.c$ate)
ate.test <- min(ate.realized)

ate.chair.test <- chair.bad.cov.c$ate.samp.dist < ate.test
ate.coun.test <- coun.bad.cov.c$ate.samp.dist < ate.test

joint.test <- ate.chair.test | ate.coun.test
p.bad.cov.c.joint <- sum(joint.test) / sims
p.bad.cov.c.joint #0.004

## Joint test w/ chairs
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- chair.good.cov.c$ate
ate.test.lower <- chair.bad.cov.c$ate

ate.good.cov.c.test <- chair.good.cov.c$ate.samp.dist > ate.test.upper
ate.bad.cov.c.test <- chair.bad.cov.c$ate.samp.dist < ate.test.lower

joint.test <- ate.good.cov.c.test & ate.bad.cov.c.test
p.chair.cov.c.joint <- sum(joint.test) / sims
p.chair.cov.c.joint #0.121

## Joint test w/ councillors
#test: probability that both coefficients will show strong effect in predicted direction under the sharp null than realized

ate.test.upper <- coun.good.cov.c$ate
ate.test.lower <- coun.bad.cov.c$ate

ate.good.cov.c.test <- coun.good.cov.c$ate.samp.dist > ate.test.upper
ate.bad.cov.c.test <- coun.bad.cov.c$ate.samp.dist < ate.test.lower

joint.test <- ate.good.cov.c.test & ate.bad.cov.c.test
p.coun.cov.c.joint <- sum(joint.test) / sims
p.coun.cov.c.joint #0.000

## Joint test of all offices
#test: probability that at least one good news effect will exceed max good news effect & at least one bad news effect will exceed min bad news effect under the sharp null

ate.test.upper <- max(chair.good.cov.c$ate,coun.good.cov.c$ate)
ate.test.lower <- min(chair.bad.cov.c$ate,coun.bad.cov.c$ate)

chair.ate.good.cov.c.test <- chair.good.cov.c$ate.samp.dist > ate.test.upper
chair.ate.bad.cov.c.test <- chair.bad.cov.c$ate.samp.dist < ate.test.lower
coun.ate.good.cov.c.test <- coun.good.cov.c$ate.samp.dist > ate.test.upper
coun.ate.bad.cov.c.test <- coun.bad.cov.c$ate.samp.dist < ate.test.lower

joint.test <- (chair.ate.good.cov.c.test | coun.ate.good.cov.c.test) & (chair.ate.bad.cov.c.test | coun.ate.bad.cov.c.test)
p.joint.cov.c <- sum(joint.test) / sims
p.joint.cov.c #0.000

test <- c("$\\text{max}(\\tilde{b}_{+}) > \\text{max}(b_{+}^*)$",
          "$\\text{min}(\\tilde{b}_{-}) < \\text{min}(b_{-}^*)$",
          "$\\tilde{b}_{\\text{chair,+}} > \\text{max}(b_{\\text{chair}}^*) \\cap \\tilde{b}_{\\text{chair,-}} < \\text{min}(b_{\\text{chair}}^*)$",
          "$\\tilde{b}_{\\text{councillor,+}} > \\text{max}(b_{\\text{councillor}}^*) \\cap \\tilde{b}_{\\text{councillor,-}} < \\text{min}(b_{\\text{councillor}}^*)$",
          "$\\text{max}(\\tilde{b}_{+}) > \\text{max}(b_{\\text{+}}^*) \\cap \\text{min}(\\tilde{b}_{\\text{-}}) < \\text{min}(b_{\\text{-}}^*)$",
          "$\\tilde{b}_{\\text{pooled,+}} > b_{\\text{pooled,+}}^*$",
          "$\\tilde{b}_{\\text{pooled,-}} < b_{\\text{pooled,-}}^*$",
          "$\\tilde{b}_{\\text{pooled,+}} > b_{\\text{pooled,+}}^* \\cap \\tilde{b}_{\\text{pooled,-}} < b_{\\text{pooled,-}}^*$")

p <- c(p.good.joint,
       p.bad.joint,
       p.chair.joint,
       p.coun.joint,
       p.joint,
       both.good$p.one.way.greater,
       both.bad$p.one.way.lesser,
       p.both.joint)
p.cov <- c(p.good.cov.joint,
           p.bad.cov.joint,
           p.chair.cov.joint,
           p.coun.cov.joint,
           p.joint.cov,
           both.good.cov$p.one.way.greater,
           both.bad.cov$p.one.way.lesser,
           p.both.joint.cov)
p.c <- c(p.good.c.joint,
         p.bad.c.joint,
         p.chair.c.joint,
         p.coun.c.joint,
         p.joint.c,
         NA,
         NA,
         NA)
p.cov.c <- c(p.good.cov.c.joint,
             p.bad.cov.c.joint,
             p.chair.cov.c.joint,
             p.coun.cov.c.joint,
             p.joint.cov.c,
             NA,
             NA,
             NA)

tab.dta <- data.frame(test,p,p.cov,p.c,p.cov.c)
print(xtable(tab.dta, digits=4), include.rownames=FALSE, sanitize.text.function=identity)


######################################################################################
###Table S25: Main results (Figure 1) with fixed-effects weights applied
######################################################################################

##### Main Subset Effects #####

chair.good <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name,
                      dta=budget.good.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                      rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                      weights=budget.good.lc5.chair.comp$fe.w)

chair.bad <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, 
                     dta=budget.bad.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                     rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                     weights=budget.bad.lc5.chair.comp$fe.w)

chair.good.cov <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name,
                          dta=budget.good.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                          weights=budget.good.lc5.chair.comp$fe.w)

chair.bad.cov <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                         dta=budget.bad.lc5.chair.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                         rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                         weights=budget.bad.lc5.chair.comp$fe.w)

coun.good <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name,
                     dta=budget.good.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                     rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                     weights=budget.good.lc5.councillor.comp$fe.w)

coun.bad <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, 
                    dta=budget.bad.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                    rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                    weights=budget.bad.lc5.councillor.comp$fe.w)

coun.good.cov <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name,
                         dta=budget.good.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                         rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                         weights=budget.good.lc5.councillor.comp$fe.w)

coun.bad.cov <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                        dta=budget.bad.lc5.councillor.comp, treat.var = "budget.treat", rand.ob=Budget_RI, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                        weights=budget.bad.lc5.councillor.comp$fe.w)

##### Verified Recipient Effects #####

chair.good.c <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name,
                        dta=budget.good.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                        rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                        weights = budget.good.lc5.chair.comp.c$fe.w)

chair.bad.c <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent | location.id | 0 | lc5.chair.name, 
                       dta=budget.bad.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                       rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                       weights = budget.bad.lc5.chair.comp.c$fe.w)

chair.good.cov.c <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name,
                            dta=budget.good.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                            rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                            weights = budget.good.lc5.chair.comp.c$fe.w)

chair.bad.cov.c <- felm.ri3(lc5.chair.inc.vote ~ budget.treat + lc5.chair.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.chair.name, 
                           dta=budget.bad.lc5.chair.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                           rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                           weights = budget.bad.lc5.chair.comp.c$fe.w)

coun.good.c <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name,
                       dta=budget.good.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                       rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                       weights=budget.good.lc5.councillor.comp.c$fe.w)

coun.bad.c <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent | location.id | 0 | lc5.councillor.name, 
                      dta=budget.bad.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                      rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                      weights=budget.bad.lc5.councillor.comp.c$fe.w)

coun.good.cov.c <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name,
                           dta=budget.good.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                           rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                           weights=budget.good.lc5.councillor.comp.c$fe.w)

coun.bad.cov.c <- felm.ri3(lc5.councillor.inc.vote ~ budget.treat + lc5.councillor.intent + b.Q1_living_conditions + b.Q21b_Trust_in_Twaweza_for_info + b.Q24_Powerful_ppl_learning_how_ + b.Q25_Will_counting_votes_be_fai + r.What_is_your_gender + r.education + r.What_is_your_age | location.id | 0 | lc5.councillor.name, 
                          dta=budget.bad.lc5.councillor.comp.c, treat.var = "budget.treat", rand.ob=Budget_RI, 
                          rand.ob.info.cols = 4, join.var = "id.cleaned", sims=9999,
                          weights=budget.bad.lc5.councillor.comp.c$fe.w)

all.ate <- c(chair.good$ate,
             chair.good.cov$ate,
             coun.good$ate,
             coun.good.cov$ate,
             chair.bad$ate,
             chair.bad.cov$ate,
             coun.bad$ate,
             coun.bad.cov$ate)
all.se <- c(chair.good$se,
             chair.good.cov$se,
             coun.good$se,
             coun.good.cov$se,
             chair.bad$se,
             chair.bad.cov$se,
             coun.bad$se,
             coun.bad.cov$se)
all.p <- c(chair.good$p.one.way.greater,
            chair.good.cov$p.one.way.greater,
            coun.good$p.one.way.greater,
            coun.good.cov$p.one.way.greater,
            chair.bad$p.one.way.lesser,
            chair.bad.cov$p.one.way.lesser,
            coun.bad$p.one.way.lesser,
            coun.bad.cov$p.one.way.lesser)

ver.ate <- c(chair.good.c$ate,
             chair.good.cov.c$ate,
             coun.good.c$ate,
             coun.good.cov.c$ate,
             chair.bad.c$ate,
             chair.bad.cov.c$ate,
             coun.bad.c$ate,
             coun.bad.cov.c$ate)
ver.se <- c(chair.good.c$se,
            chair.good.cov.c$se,
            coun.good.c$se,
            coun.good.cov.c$se,
            chair.bad.c$se,
            chair.bad.cov.c$se,
            coun.bad.c$se,
            coun.bad.cov.c$se)
ver.p <- c(chair.good.c$p.one.way.greater,
           chair.good.cov.c$p.one.way.greater,
           coun.good.c$p.one.way.greater,
           coun.good.cov.c$p.one.way.greater,
           chair.bad.c$p.one.way.lesser,
           chair.bad.cov.c$p.one.way.lesser,
           coun.bad.c$p.one.way.lesser,
           coun.bad.cov.c$p.one.way.lesser)

#Formatting functions
coef.print <- function(vector){
  sprintf("%.3f",round(vector,3))
}

se.print <- function(vector){
  paste("(",sprintf("%.3f",round(vector,3)),")",sep="")
}

p.print <- function(vector){
  paste("p=",sprintf("%.3f", round(vector,3)),sep="")
}

all.dta <- rbind(coef.print(all.ate),
                 se.print(all.se),
                 p.print(all.p))
stargazer(all.dta) #Post-formating in LaTex required

ver.dta <- rbind(coef.print(ver.ate),
                 se.print(ver.se),
                 p.print(ver.p))
stargazer(ver.dta) #Post-formating in LaTex required


#options(warn=0)
#Note: warnings turned back on after compiling replication report